From f9ca2237ffb66a7ac210d8696182d5170d046046 Mon Sep 17 00:00:00 2001 From: Steve McIntyre <93sam@debian.org> Date: Mon, 24 Mar 2008 15:08:58 +0000 Subject: [PATCH] Re-split link.pl code out; add_files needs it too --- debian/changelog | 4 +-- tools/link.pl | 68 ++++++++++++++++++++++++++++++++++++++++ tools/make_disc_trees.pl | 60 ++--------------------------------- 3 files changed, 72 insertions(+), 60 deletions(-) create mode 100644 tools/link.pl diff --git a/debian/changelog b/debian/changelog index 9fb9158f..a546ea7b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,8 +2,8 @@ debian-cd (3.0.5) UNRELEASED; urgency=low * 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 - Needs a small re-arrangement: code from tools/add_packages and - tools/link.pl now moves into tools/make_disc_trees.pl + Needs a small re-arrangement: code from tools/add_packages now + moves into tools/make_disc_trees.pl -- Steve McIntyre <93sam@debian.org> Mon, 17 Mar 2008 23:25:12 +0000 diff --git a/tools/link.pl b/tools/link.pl new file mode 100644 index 00000000..34832e54 --- /dev/null +++ b/tools/link.pl @@ -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; diff --git a/tools/make_disc_trees.pl b/tools/make_disc_trees.pl index 7a51f22a..af83f444 100755 --- a/tools/make_disc_trees.pl +++ b/tools/make_disc_trees.pl @@ -38,6 +38,8 @@ my $symlink_farm = $ENV{'SYMLINK'} || 0; my $link_verbose = $ENV{'VERBOSE'} || 0; my $link_copy = $ENV{'COPYLINK'} || 0; +require "$basedir/tools/link.pl"; + if (defined($ENV{'MAXCDS'})) { $maxcds = $ENV{'MAXCDS'}; } else { @@ -1011,61 +1013,3 @@ sub add_packages { $/ = $old_split; # Return to line-orientation 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; -}