Explorar el Código

scripts: Switch all find(1) command calls to File::Find

The find(1) command has subtle behavior differences depending on the
implementation (for example BSD vs GNU), the perl module is more portable
and has a more consistent behavior, such as always canonicalizing the
pathnames.

Closes: #800649
Guillem Jover hace 10 años
padre
commit
3f8099b21b
Se han modificado 3 ficheros con 25 adiciones y 21 borrados
  1. 3 0
      debian/changelog
  2. 14 14
      scripts/dpkg-scanpackages.pl
  3. 8 7
      scripts/dpkg-scansources.pl

+ 3 - 0
debian/changelog

@@ -1,6 +1,9 @@
 dpkg (1.18.4) UNRELEASED; urgency=low
 
   [ Guillem Jover ]
+  * Switch dpkg-scansources and dpkg-scanpackages to use File::Find instead
+    of find(1), as the former is more portable with more consistent behavior,
+    and always canonicalizes the pathnames. Closes: #800649
   * Documentation:
     - Move description for “target architecture” from the dpkg-architecture(1)
       ‘-A’ option to the TERMS section. Closes: #799046

+ 14 - 14
scripts/dpkg-scanpackages.pl

@@ -21,6 +21,7 @@ use warnings;
 use strict;
 
 use Getopt::Long qw(:config posix_default bundling no_ignorecase);
+use File::Find;
 
 use Dpkg ();
 use Dpkg::Gettext;
@@ -230,15 +231,6 @@ foreach my $alg (keys %hash) {
     }
 }
 
-my @find_args;
-if ($options{arch}) {
-     @find_args = ('(', '-name', "*_all.$type", '-o',
-			'-name', "*_${arch}.$type", ')');
-}
-else {
-     @find_args = ('-name', "*.$type");
-}
-
 my ($binarydir, $override, $pathprefix) = @ARGV;
 
 if (not -d $binarydir) {
@@ -250,13 +242,21 @@ if (defined $override and not -e $override) {
 
 $pathprefix //= '';
 
-open my $find_h, '-|', 'find', '-L', "$binarydir/", @find_args, '-print'
-     or syserr(g_("couldn't open %s for reading"), $binarydir);
-while (my $fn = <$find_h>) {
-    chomp $fn;
+my $find_filter;
+if ($options{arch}) {
+    $find_filter = qr/_(?:all|${arch})\.$type$/;
+} else {
+    $find_filter = qr/\.$type$/;
+}
+my @archives;
+my $scan_archives = sub {
+    push @archives, $File::Find::name if m/$find_filter/;
+};
+
+find({ follow => 1, wanted => $scan_archives}, $binarydir);
+foreach my $fn (@archives) {
     process_deb($pathprefix, $fn);
 }
-close($find_h);
 
 load_override($override) if defined $override;
 load_override_extra($options{'extra-override'}) if defined $options{'extra-override'};

+ 8 - 7
scripts/dpkg-scansources.pl

@@ -21,6 +21,7 @@ use strict;
 use warnings;
 
 use Getopt::Long qw(:config posix_default bundling no_ignorecase);
+use File::Find;
 
 use Dpkg ();
 use Dpkg::Gettext;
@@ -303,22 +304,22 @@ load_override $override if defined $override;
 load_src_override $src_override, $override;
 load_override_extra $extra_override_file if defined $extra_override_file;
 
-open my $find_fh, '-|', 'find', '-L', $dir, '-name', '*.dsc', '-print'
-    or syserr(g_('cannot fork for %s'), 'find');
-while (<$find_fh>) {
-    chomp;
-    s{^\./+}{};
+my @dsc;
+my $scan_dsc = sub {
+    push @dsc, $File::Find::name if m/\.dsc$/;
+};
 
+find({ follow => 1, wanted => $scan_dsc }, $dir);
+foreach my $fn (@dsc) {
     # FIXME: Fix it instead to not die on syntax and general errors?
     eval {
-        process_dsc($prefix, $_);
+        process_dsc($prefix, $fn);
     };
     if ($@) {
         warn $@;
         next;
     }
 }
-close $find_fh or syserr(g_('error closing %s (%s)'), 'find', $!);
 
 if (not $no_sort) {
     @sources = sort {