Re-split link.pl code out; add_files needs it too

This commit is contained in:
Steve McIntyre 2008-03-24 15:08:58 +00:00
parent 2f46e78135
commit f9ca2237ff
3 changed files with 72 additions and 60 deletions

4
debian/changelog vendored
View File

@ -2,8 +2,8 @@ debian-cd (3.0.5) UNRELEASED; urgency=low
* Pre-cache apt's package information in large lumps rather than walk * Pre-cache apt's package information in large lumps rather than walk
through it one package at a time. It's much faster. Closes: #470838 through it one package at a time. It's much faster. Closes: #470838
Needs a small re-arrangement: code from tools/add_packages and Needs a small re-arrangement: code from tools/add_packages now
tools/link.pl now moves into tools/make_disc_trees.pl moves into tools/make_disc_trees.pl
-- Steve McIntyre <93sam@debian.org> Mon, 17 Mar 2008 23:25:12 +0000 -- Steve McIntyre <93sam@debian.org> Mon, 17 Mar 2008 23:25:12 +0000

68
tools/link.pl Normal file
View File

@ -0,0 +1,68 @@
#!/usr/bin/perl -w
use strict;
my $symlink_farm = $ENV{'SYMLINK'} || 0;
my $link_verbose = $ENV{'VERBOSE'} || 0;
my $link_copy = $ENV{'COPYLINK'} || 0;
sub good_link ($$) {
my ($src, $dest) = @_;
my $dir_added = 0;
if (! -e $dest) {
# Check if the destination directory does exist
my $ddir = $dest;
$ddir =~ s#/?[^/]+$##g;
if ($ddir eq "")
{
$ddir = ".";
}
if (! -d $ddir) # Create it if not
{
system("mkdir -p $ddir");
$dir_added++;
}
# Link the files
if ($symlink_farm) {
print "Symlink: $dest => $src\n" if ($link_verbose >= 3);
if (not symlink ($src, $dest)) {
print STDERR "Symlink from $src to $dest failed: $!\n";
}
} elsif ($link_copy) {
print "Copy: $dest => $src\n" if ($link_verbose >= 3);
if (system("cp -ap $src $dest")) {
my $err_num = $? >> 8;
my $sig_num = $? & 127;
print STDERR "Copy from $src to $dest failed: cp exited with error code $err_num, signal $sig_num\n";
}
} else {
print "Hardlink: $dest => $src\n" if ($link_verbose >= 3);
if (not link ($src, $dest)) {
print STDERR "Link from $src to $dest failed: $!\n";
}
}
}
return $dir_added;
}
sub real_file ($) {
my $link = shift;
my ($dir, $to);
while (-l $link) {
$dir = $link;
$dir =~ s#[^/]+/?$##;
if ($to = readlink($link)) {
$link = $dir . $to;
} else {
print STDERR "Can't readlink $link: $!\n";
}
}
return $link;
}
1;

View File

@ -38,6 +38,8 @@ my $symlink_farm = $ENV{'SYMLINK'} || 0;
my $link_verbose = $ENV{'VERBOSE'} || 0; my $link_verbose = $ENV{'VERBOSE'} || 0;
my $link_copy = $ENV{'COPYLINK'} || 0; my $link_copy = $ENV{'COPYLINK'} || 0;
require "$basedir/tools/link.pl";
if (defined($ENV{'MAXCDS'})) { if (defined($ENV{'MAXCDS'})) {
$maxcds = $ENV{'MAXCDS'}; $maxcds = $ENV{'MAXCDS'};
} else { } else {
@ -1011,61 +1013,3 @@ sub add_packages {
$/ = $old_split; # Return to line-orientation $/ = $old_split; # Return to line-orientation
return $total_blocks; return $total_blocks;
} }
sub good_link ($$) {
my ($src, $dest) = @_;
my $dir_added = 0;
if (! -e $dest) {
# Check if the destination directory does exist
my $ddir = $dest;
$ddir =~ s#/?[^/]+$##g;
if ($ddir eq "")
{
$ddir = ".";
}
if (! -d $ddir) # Create it if not
{
system("mkdir -p $ddir");
$dir_added++;
}
# Link the files
if ($symlink_farm) {
print "Symlink: $dest => $src\n" if ($link_verbose >= 3);
if (not symlink ($src, $dest)) {
print STDERR "Symlink from $src to $dest failed: $!\n";
}
} elsif ($link_copy) {
print "Copy: $dest => $src\n" if ($link_verbose >= 3);
if (system("cp -ap $src $dest")) {
my $err_num = $? >> 8;
my $sig_num = $? & 127;
print STDERR "Copy from $src to $dest failed: cp exited with error code $err_num, signal $sig_num\n";
}
} else {
print "Hardlink: $dest => $src\n" if ($link_verbose >= 3);
if (not link ($src, $dest)) {
print STDERR "Link from $src to $dest failed: $!\n";
}
}
}
return $dir_added;
}
sub real_file ($) {
my $link = shift;
my ($dir, $to);
while (-l $link) {
$dir = $link;
$dir =~ s#[^/]+/?$##;
if ($to = readlink($link)) {
$link = $dir . $to;
} else {
print STDERR "Can't readlink $link: $!\n";
}
}
return $link;
}