Software Freedom Law Center

Changeset 212

Show
Ignore:
Timestamp:
11/23/08 16:07:59 (1 month ago)
Author:
bkuhn
Message:

Switched to use File::Find

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/small-hacks/perl/hierarchy-comparison

    • Property svn:executable set to *
    r210 r212  
    2929###################################################################### 
    3030sub FindAndSortOutput { 
    31   my($findCmd, $dir, $output, $ignoreRegex) = @_; 
     31  use File::Find; 
     32 
     33  my($type, $dir, $output, $ignoreRegex) = @_; 
    3234  my @files; 
    3335 
    34   my $curdir = getcwd(); 
     36  my $buildList = sub {  
     37    if ($type eq "NON-REGULAR") { 
     38      push(@files, $_) unless -f $_; 
     39    } elsif ($type eq "FILES") { 
     40      push(@files, $_) if -f $_; 
     41    } elsif ($type eq "DIRECTORY") { 
     42      push(@files, $_) if -d $_; 
     43    } else { 
     44      die "Unknown type requested: $type"; 
     45    } 
     46  }; 
    3547 
    36   chdir $dir or die "$0: cannot change into $dir: $!"; 
    37  
    38   open(FILES, "$findCmd |") or 
    39     die "$0: cannot run $findCmd in $dir: $!"; 
    40  
    41   @files = <FILES>; 
    42   close FILES; 
    43   die "$0: error running find command; $!" unless ($? == 0); 
     48  find({ wanted => $buildList, no_chdir => 1},  $dir); 
    4449 
    4550  open(FILE_OUTPUT, ">$output") or 
     
    5560  close FILE_OUTPUT; 
    5661 
    57   chdir $curdir or die "$0: cannot go back into $curdir: $!"; 
    5862  return @sortedChompedFiles; 
    5963} 
     
    6771 
    6872#  open(FILE_OUTPUT, "|/usr/bin/xargs /usr/bin/md5sum >$outputFile 2>&1") 
    69   open(FILE_OUTPUT, "|/usr/bin/xargs /usr/bin/md5sum >$outputFile") 
     73  open(FILE_OUTPUT, "|/usr/bin/xargs -0 /usr/bin/md5sum >$outputFile") 
    7074    or die "unable to write to $outputFile: $!"; 
    7175 
    7276  foreach my $file (@{$fileListRef}) { 
    73     print FILE_OUTPUT "$file\n"; 
     77    print FILE_OUTPUT "$file\000"; 
    7478  } 
    7579  close FILE_OUTPUT; 
     
    96100print "Doing directory comparision: "; 
    97101 
    98 my $dirFindCmd = "/usr/bin/find . -type d -print 2>&1"; 
    99  
    100 my(@orgDirs) = FindAndSortOutput($dirFindCmd, $origDir, $origTempFile, 
     102my(@orgNonRegular) = FindAndSortOutput("NON-REGULAR", $origDir, $origTempFile, 
    101103                                 $ignoreRegex); 
    102 my(@comparedDirs) = FindAndSortOutput($dirFindCmd, $comparedDir, 
     104my(@comparedNonRegular) = FindAndSortOutput("NON-REGULAR", $comparedDir, 
    103105                                      $comparedTempFile, $ignoreRegex); 
    104106 
     
    123125print "Doing file hierarchy comparision: "; 
    124126 
    125 my $fileFindCmd = "/usr/bin/find . -type f -print 2>&1"; 
    126  
    127 my(@orgFiles) = FindAndSortOutput($fileFindCmd, $origDir, $origTempFile, 
     127my(@orgFiles) = FindAndSortOutput("FILES", $origDir, $origTempFile, 
    128128                                 $ignoreRegex); 
    129 my(@comparedFiles) = FindAndSortOutput($fileFindCmd, $comparedDir, 
     129my(@comparedFiles) = FindAndSortOutput("FILES", $comparedDir, 
    130130                                       $comparedTempFile, $ignoreRegex); 
    131131 

SFLC Main Page

[frdm] Support SFLC