]> arthur.barton.de Git - netatalk.git/blob - contrib/shell_utils/apple_cp
Updated perl.
[netatalk.git] / contrib / shell_utils / apple_cp
1 #! /usr/bin/perl
2
3 # $Header: /home/ralph/netatalk/rsync/netatalk/contrib/shell_utils/Attic/apple_cp,v 1.3 2001-10-16 18:27:27 lancel Exp $
4 #
5 # $Log: apple_cp,v $
6 # Revision 1.3  2001-10-16 18:27:27  lancel
7 # Updated perl.
8 #
9 # Fixed a failing test where $to wasn't a directory, but
10 # didn't check that $from was only a single file, result file to file
11 # always failed.
12 #
13 # Fixed the .AppleDouble variable being sent to the split_dir_file
14 # function, it was mistakenly sending $from instead of $to, result cp
15 # $from $from, same file.
16 #
17 # Revision 1.2  2000/08/09 14:12:06  rufustfirefly
18 # /usr/local/bin/perl -> /usr/bin/perl and portability fixes
19 #
20 # Revision 1.1  2000/08/09 14:08:06  rufustfirefly
21 # Shell utils from http://www.-genome.wi.mit.edu/ftp/distribution/software/Bass/bass-1.29/apple_util/ (initial import)
22 #
23 # Revision 1.1  1996/04/03 02:13:12  lstein
24 # Added all these files because they're essential utilities.
25 #
26 # Revision 1.2  1996/02/09  18:44:44  will
27 # fix to usage string
28 #
29 # Revision 1.1  1996/02/09  18:21:35  will
30 # Initial revision
31 #
32 #
33
34 $USAGE = <<USAGE;
35 Usage: $0 filename1 filename2
36        $0 filename ...  directory
37 Do an apple copy, copying the resource fork as well
38 USAGE
39
40 die $USAGE if @ARGV < 2;
41
42 @from = @ARGV; pop(@from);
43 $to = $ARGV[-1];
44
45 if (-f $to && @from > 1) { die $USAGE; }
46
47 foreach $from (@from) {
48     if (!-f $from) {    
49         print STDERR "file $from does not exist\n";
50         die $USAGE;
51     }
52     
53     if (!-d $to && @from >1) {
54         print STDERR "directory $to does not exist\nCan't copy multiple files into one file.\n";
55         die $USAGE;
56     }
57     
58     $cmd = "cp '$from' '$to'";
59     system $cmd || die "error executing $cmd";
60     
61     ($from_dir, $from_file) = split_dir_file($from);
62
63     if (-d $to) {
64         if (!-d "$to/.AppleDouble") {
65             mkdir("$to/.AppleDouble", 0777);
66         }       
67         $cmd = "cp '$from_dir/.AppleDouble/$from_file' '$to/.AppleDouble/$from_file'";
68     } else {
69         ($to_dir, $to_file) = split_dir_file($to);
70         if (!-d "$to_dir/.AppleDouble") {
71             mkdir("$to_dir/.AppleDouble", 0777);
72         }       
73         $cmd = "cp '$from_dir/.AppleDouble/$from_file' '$to_dir/.AppleDouble/$to_file'";
74     }
75
76     system $cmd || die "error executing $cmd";
77 }
78
79 # split a file path into a directory and file name.
80 sub split_dir_file {
81     my $path = shift;
82
83     @path_elems = split(/\//, $path);
84
85     my $file = pop(@path_elems);
86     my $dir;
87     if (!@path_elems) {
88         $dir = '.';
89     } else {
90         $dir = join('/', @path_elems);
91     }
92
93     $dir, $file;
94 }
95
96