~ubuntu-branches/ubuntu/precise/netatalk/precise

« back to all changes in this revision

Viewing changes to contrib/shell_utils/apple_cp.in

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Rittau
  • Date: 2004-01-19 12:43:49 UTC
  • Revision ID: james.westby@ubuntu.com-20040119124349-es563jbp0hk0ae51
Tags: upstream-1.6.4
ImportĀ upstreamĀ versionĀ 1.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@PERL@
 
2
 
3
# $Id: apple_cp.in,v 1.1 2002/01/17 05:59:25 srittau Exp $
 
4
 
 
5
$USAGE = <<USAGE;
 
6
Usage: $0 filename1 filename2
 
7
       $0 filename ...  directory
 
8
Do an apple copy, copying the resource fork as well
 
9
USAGE
 
10
 
 
11
die $USAGE if @ARGV < 2;
 
12
 
 
13
@from = @ARGV; pop(@from);
 
14
$to = $ARGV[-1];
 
15
 
 
16
if (-f $to && @from > 1) { die $USAGE; }
 
17
 
 
18
foreach $from (@from) {
 
19
    if (!-f $from) {    
 
20
        print STDERR "file $from does not exist\n";
 
21
        die $USAGE;
 
22
    }
 
23
    
 
24
    if (!-d $to && @from >1) {
 
25
        print STDERR "directory $to does not exist\nCan't copy multiple files into one file.\n";
 
26
        die $USAGE;
 
27
    }
 
28
    
 
29
    $cmd = "cp '$from' '$to'";
 
30
    system $cmd || die "error executing $cmd";
 
31
    
 
32
    ($from_dir, $from_file) = split_dir_file($from);
 
33
 
 
34
    if (-d $to) {
 
35
        if (!-d "$to/.AppleDouble") {
 
36
            mkdir("$to/.AppleDouble", 0777);
 
37
        }       
 
38
        $cmd = "cp '$from_dir/.AppleDouble/$from_file' '$to/.AppleDouble/$from_file'";
 
39
    } else {
 
40
        ($to_dir, $to_file) = split_dir_file($to);
 
41
        if (!-d "$to_dir/.AppleDouble") {
 
42
            mkdir("$to_dir/.AppleDouble", 0777);
 
43
        }       
 
44
        $cmd = "cp '$from_dir/.AppleDouble/$from_file' '$to_dir/.AppleDouble/$to_file'";
 
45
    }
 
46
 
 
47
    system $cmd || die "error executing $cmd";
 
48
}
 
49
 
 
50
# split a file path into a directory and file name.
 
51
sub split_dir_file {
 
52
    my $path = shift;
 
53
 
 
54
    @path_elems = split(/\//, $path);
 
55
 
 
56
    my $file = pop(@path_elems);
 
57
    my $dir;
 
58
    if (!@path_elems) {
 
59
        $dir = '.';
 
60
    } else {
 
61
        $dir = join('/', @path_elems);
 
62
    }
 
63
 
 
64
    $dir, $file;
 
65
}
 
66
 
 
67