Changeset 212
- Timestamp:
- 11/23/08 16:07:59 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/small-hacks/perl/hierarchy-comparison
- Property svn:executable set to *
r210 r212 29 29 ###################################################################### 30 30 sub FindAndSortOutput { 31 my($findCmd, $dir, $output, $ignoreRegex) = @_; 31 use File::Find; 32 33 my($type, $dir, $output, $ignoreRegex) = @_; 32 34 my @files; 33 35 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 }; 35 47 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); 44 49 45 50 open(FILE_OUTPUT, ">$output") or … … 55 60 close FILE_OUTPUT; 56 61 57 chdir $curdir or die "$0: cannot go back into $curdir: $!";58 62 return @sortedChompedFiles; 59 63 } … … 67 71 68 72 # 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") 70 74 or die "unable to write to $outputFile: $!"; 71 75 72 76 foreach my $file (@{$fileListRef}) { 73 print FILE_OUTPUT "$file\ n";77 print FILE_OUTPUT "$file\000"; 74 78 } 75 79 close FILE_OUTPUT; … … 96 100 print "Doing directory comparision: "; 97 101 98 my $dirFindCmd = "/usr/bin/find . -type d -print 2>&1"; 99 100 my(@orgDirs) = FindAndSortOutput($dirFindCmd, $origDir, $origTempFile, 102 my(@orgNonRegular) = FindAndSortOutput("NON-REGULAR", $origDir, $origTempFile, 101 103 $ignoreRegex); 102 my(@compared Dirs) = FindAndSortOutput($dirFindCmd, $comparedDir,104 my(@comparedNonRegular) = FindAndSortOutput("NON-REGULAR", $comparedDir, 103 105 $comparedTempFile, $ignoreRegex); 104 106 … … 123 125 print "Doing file hierarchy comparision: "; 124 126 125 my $fileFindCmd = "/usr/bin/find . -type f -print 2>&1"; 126 127 my(@orgFiles) = FindAndSortOutput($fileFindCmd, $origDir, $origTempFile, 127 my(@orgFiles) = FindAndSortOutput("FILES", $origDir, $origTempFile, 128 128 $ignoreRegex); 129 my(@comparedFiles) = FindAndSortOutput( $fileFindCmd, $comparedDir,129 my(@comparedFiles) = FindAndSortOutput("FILES", $comparedDir, 130 130 $comparedTempFile, $ignoreRegex); 131 131