| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# First arg, the root of the destination |
| 4 |
# Second arg, the root of the source |
| 5 |
# Other args, the directories/files to copy (relative to the root source) |
| 6 |
|
| 7 |
use strict; |
| 8 |
use File::Find; |
| 9 |
|
| 10 |
my $basedir = $ENV{'BASEDIR'} || die; |
| 11 |
require "$basedir/tools/link.pl"; |
| 12 |
|
| 13 |
my $rootdest = shift || die ; |
| 14 |
my $rootsrc = shift || die ; |
| 15 |
my @files = @ARGV; |
| 16 |
my $verbose = $ENV{'VERBOSE'} || 0; |
| 17 |
|
| 18 |
chdir $rootsrc; |
| 19 |
|
| 20 |
sub relative ($) { |
| 21 |
my $file = shift; |
| 22 |
$file =~ s#^/*$rootsrc/##; |
| 23 |
return $file; |
| 24 |
} |
| 25 |
|
| 26 |
sub mkdirs { |
| 27 |
if (-d and not -l) { |
| 28 |
my $dir = "$rootdest/" . relative($File::Find::name); |
| 29 |
return if -d $dir; |
| 30 |
print "Creating $dir directory ...\n" if ($verbose >= 2); |
| 31 |
|
| 32 |
if (not mkdir ($dir, 0775)) { |
| 33 |
print STDERR "Cannot mkdir $dir : $!\n"; |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
sub add_files { |
| 39 |
if (-f and not -l) { |
| 40 |
good_link ("$rootsrc/" . relative($File::Find::name), |
| 41 |
"$rootdest/" . relative($File::Find::name)); |
| 42 |
} elsif (-l) { |
| 43 |
#Check if the link is valid in the desttree otherwise |
| 44 |
#hardlink it |
| 45 |
my $file = $File::Find::name; |
| 46 |
$file =~ s#/[^/]+$##; |
| 47 |
$file .= "/" . readlink; |
| 48 |
if (-e "$rootdest/" . relative($file)) { |
| 49 |
good_link ("$rootsrc/" . relative($File::Find::name), |
| 50 |
"$rootdest/" . relative($File::Find::name)); |
| 51 |
} else { |
| 52 |
$file = real_file ("$rootsrc/$File::Find::name"); |
| 53 |
good_link ($file, |
| 54 |
"$rootdest/" . relative($File::Find::name)); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
find (\&mkdirs, @files); |
| 60 |
find (\&add_files, @files); |
| 61 |
|