Difference between
modified post f0b64 by Anonymous on Sat 22nd Sep 2012 13:05
original post 971d62 by Anonymous on Sat 22nd Sep 2012 09:46
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | #!/usr/bin/perl | |
| 2 | 2 | ||
| 3 | 3 | use 5.12.3; | |
| 4 | 4 | use strict; | |
| 5 | 5 | use warnings; | |
| 6 | 6 | use Cwd qw(abs_path cwd); | |
| 7 | 7 | use Digest::MD5 qw(md5_hex); | |
| 8 | 8 | use IO::Handle qw(autoflush); | |
| 9 | 9 | use File::Basename qw(basename dirname); | |
| 10 | 10 | #use File::Slurp qw(read_file); | |
| 11 | 11 | use diagnostics; | |
| 12 | 12 | ||
| 13 | 13 | use threads qw(yield); | |
| 14 | 14 | use threads::shared; | |
| 15 | 15 | use Thread::Queue; | |
| 16 | 16 | use Thread::Semaphore; | |
| 17 | 17 | #use Fcntl qw(:flock); | |
| 18 | 18 | use POSIX qw(SIGINT); | |
| 19 | 19 | use POSIX qw(ceil); | |
| 20 | 20 | ||
| 21 | 21 | chomp(my $cores = `grep -c ^processor /proc/cpuinfo`); | |
| 22 | 22 | ||
| 23 | 23 | my (@lib, $mode); | |
| 24 | 24 | ||
| 25 | 25 | # Path to and name of log file to be used for logging. | |
| 26 | 26 | my $logf = "$ENV{HOME}/md5db.log"; | |
| 27 | 27 | ||
| 28 | 28 | # Delimiter used for database | |
| 29 | 29 | my $delim = "\t\*\t"; | |
| 30 | 30 | ||
| 31 | 31 | # Array for storing the actual arguments used by the script internally. | |
| 32 | 32 | # Might be useful for debugging. | |
| 33 | 33 | my @cmd = (basename($0)); | |
| 34 | 34 | ||
| 35 | 35 | # Name of database file. | |
| 36 | 36 | my $db = 'md5.db'; | |
| 37 | 37 | ||
| 38 | 38 | # Clear screen command. | |
| 39 | 39 | my $clear = `clear && echo`; | |
| 40 | 40 | ||
| 41 | 41 | # Creating a hash that will store the names of files that are | |
| 42 | 42 | # too big to fit into RAM. We'll process them last. | |
| 43 | - | my %large; | |
| 43 | + | my %large :shared; | |
| 44 | 44 | ||
| 45 | 45 | # Creating a few shared variables. | |
| 46 | 46 | # %err will be used for errors | |
| 47 | 47 | # $n will be used to count the number of files processed | |
| 48 | 48 | # %md5h is the database hash | |
| 49 | 49 | my %err :shared; | |
| 50 | 50 | my $n :shared = 0; | |
| 51 | 51 | my %md5h :shared; | |
| 52 | 52 | my %file_contents :shared; | |
| 53 | 53 | my $stopping :shared = 0; | |
| 54 | 54 | my $file_stack :shared = 0; | |
| 55 | 55 | my $busy :shared = 0; | |
| 56 | - | my @parts :shared = (0) x 2; | |
| 57 | 56 | ||
| 58 | - | my $disk_size = 500000000; | |
| 57 | + | my $disk_size = 1000000000; | |
| 59 | 58 | ||
| 60 | 59 | # This will be used to control access to the logger subroutine. | |
| 61 | 60 | my $semaphore = Thread::Semaphore->new(); | |
| 62 | 61 | ||
| 63 | 62 | POSIX::sigaction(SIGINT, POSIX::SigAction->new(\&handler)) | |
| 64 | 63 | || die "Error setting SIGINT handler: $!\n"; | |
| 65 | 64 | ||
| 66 | 65 | # Creating a custom POSIX signal handler. | |
| 67 | 66 | # First we create a shared variable that will work as a SIGINT switch. | |
| 68 | 67 | # Then we define the handler subroutine. | |
| 69 | 68 | # If ^C is pressed for the first time, | |
| 70 | 69 | # trip the switch and let the current threads finish. | |
| 71 | 70 | # If ^C is pressed a second time, quit directly. | |
| 72 | 71 | # Each subroutine to be used for starting threads will have to | |
| 73 | 72 | # take notice of the state of the $saw_sigint variable. | |
| 74 | 73 | my $saw_sigint :shared = 0; | |
| 75 | 74 | sub handler { | |
| 76 | 75 | if ($saw_sigint == 1) { | |
| 77 | 76 | logger('int', $n); | |
| 78 | 77 | hash2file(); | |
| 79 | 78 | exit; | |
| 80 | 79 | } else { $saw_sigint = 1; } | |
| 81 | 80 | } | |
| 82 | 81 | ||
| 83 | 82 | # Open file handle for the log file | |
| 84 | 83 | open(my $LOG, '>>', $logf) or die "Can't open '$logf': $!"; | |
| 85 | 84 | ||
| 86 | 85 | # Make the $LOG file handle unbuffered for instant logging. | |
| 87 | 86 | $LOG->autoflush(1); | |
| 88 | 87 | ||
| 89 | 88 | # Duplicate STDERR as a regular file handle | |
| 90 | 89 | open(my $SE, ">&STDERR") or die "Can't duplicate STDERR: $!"; | |
| 91 | 90 | ||
| 92 | 91 | ### Subroutine for printing usage instructions | |
| 93 | 92 | sub usage { | |
| 94 | 93 | ||
| 95 | 94 | my $s = basename($0); | |
| 96 | 95 | ||
| 97 | 96 | say <<"HELP" | |
| 98 | 97 | Usage: $s [options] [directory 1] .. [directory N] | |
| 99 | 98 | ||
| 100 | 99 | -help Print this help message. | |
| 101 | 100 | ||
| 101 | + | -double Check database for files that have identical | |
| 102 | 104 | -import Import MD5 sums to the database from already existing | |
| 103 | 105 | \*.MD5 files in each directory. | |
| 104 | 106 | ||
| 105 | 107 | -index Index new files in each directory. | |
| 106 | 108 | ||
| 107 | 109 | -test Test the MD5 sums of the files in the database to see if | |
| 108 | 110 | they've changed. | |
| 109 | 111 | ||
| 110 | 112 | HELP | |
| 111 | 113 | } | |
| 112 | 114 | ||
| 113 | 115 | # This loop goes through the argument list as passed to the script | |
| 114 | 116 | # by the user when ran. | |
| 115 | 117 | foreach my $arg (@ARGV) { | |
| 116 | 118 | ||
| 117 | 119 | # If argument starts with a dash '-', interprete it as an option | |
| 118 | 120 | if ($arg =~ /^-/) { | |
| 119 | 121 | ||
| 120 | 122 | given ($arg) { | |
| 123 | + | # When '-double', set script mode to 'double', and call | |
| 121 | 128 | ||
| 122 | 129 | # When '-import', set script mode to 'import', and call | |
| 123 | 130 | # the md5import subroutine later. | |
| 124 | 131 | when (/^-import$/) { | |
| 125 | 132 | if (!$mode) { push(@cmd, $arg); $mode = 'import'; } | |
| 126 | 133 | } | |
| 127 | 134 | ||
| 128 | 135 | # When '-help', set script mode to 'help', and print | |
| 129 | 136 | # usage instructions later. | |
| 130 | 137 | when (/^-help$/) { | |
| 131 | 138 | if (!$mode) { push(@cmd, $arg); $mode = 'help'; } | |
| 132 | 139 | } | |
| 133 | 140 | ||
| 134 | 141 | # When '-index', set script mode to 'index', and call | |
| 135 | 142 | # the md5index subroutine later. | |
| 136 | 143 | when (/^-index$/) { | |
| 137 | 144 | if (!$mode) { push(@cmd, $arg); $mode = 'index'; } | |
| 138 | 145 | } | |
| 139 | 146 | ||
| 140 | 147 | # When '-test', set the script mode to 'test', and call | |
| 141 | 148 | # the md5test subroutine later. | |
| 142 | 149 | when (/^-test$/) { | |
| 143 | 150 | if (!$mode) { push(@cmd, $arg); $mode = 'test'; } | |
| 144 | 151 | } | |
| 145 | 152 | } | |
| 146 | 153 | # If argument is a directory, include it in the @lib array | |
| 147 | 154 | } elsif (-d $arg) { push(@lib, $arg); push(@cmd, $arg); } | |
| 148 | 155 | } | |
| 149 | 156 | ||
| 150 | 157 | # If no switches were used, print usage instructions | |
| 151 | - | if (!@lib || | |
| 158 | + | if (!@lib || !$mode || $mode eq 'help') | |
| 154 | 159 | { usage; exit; } | |
| 155 | 160 | ||
| 156 | 161 | #say "@cmd\n"; | |
| 157 | 162 | ||
| 158 | 163 | # Subroutine for controlling the log file | |
| 159 | 164 | # Applying a semaphore so multiple threads won't try to | |
| 160 | 165 | # access it at once, just in case ;-) | |
| 161 | 166 | sub logger { | |
| 162 | 167 | ||
| 163 | 168 | $semaphore->down(); | |
| 164 | 169 | ||
| 165 | 170 | my($arg, $sw, @fn, $n); | |
| 166 | 171 | ||
| 167 | 172 | # Creating a variable to hold the current time. | |
| 168 | 173 | my $now = localtime(time); | |
| 169 | 174 | ||
| 170 | 175 | # Array of accepted switches to this subroutine | |
| 171 | 176 | my @larg = qw{start int gone corr diff end}; | |
| 172 | 177 | ||
| 173 | 178 | # Loop through all the arguments passed to this subroutine | |
| 174 | 179 | # Perform checks that decide which variable the arguments are to | |
| 175 | 180 | # be assigned to. | |
| 176 | 181 | CHECK: while (@_) { | |
| 177 | 182 | $arg = shift(@_); | |
| 178 | 183 | ||
| 179 | 184 | # If $arg is a switch, set the $sw variable and start | |
| 180 | 185 | # the next iteration of the CHECK loop. | |
| 181 | 186 | foreach (@larg) { | |
| 182 | 187 | if ($_ eq $arg) { $sw = $arg; next CHECK; } | |
| 183 | 188 | } | |
| 184 | 189 | ||
| 185 | 190 | # If $arg is a number assign it to $n, if it's a file | |
| 186 | 191 | # add it to @fn. | |
| 187 | 192 | if ($arg =~ /^[0-9]*$/) { $n = $arg; } | |
| 188 | 193 | else { push(@fn, $arg); } | |
| 189 | 194 | } | |
| 190 | 195 | given ($sw) { | |
| 191 | 196 | # Starts writing the log. | |
| 192 | 197 | when ('start') { | |
| 193 | 198 | say $LOG "\n**** Logging started on $now ****\n"; | |
| 194 | 199 | say $LOG "Running script in '$mode' mode.\n"; | |
| 195 | 200 | } | |
| 196 | 201 | # When the script is interrupted by user pressing ^C, | |
| 197 | 202 | # say so in STDOUT, close the log. | |
| 198 | 203 | when ('int') { | |
| 199 | 204 | say "\nInterrupted by user!\n"; | |
| 200 | 205 | say $LOG $n . " file(s) were tested."; | |
| 201 | 206 | say $LOG "\n**** Logging ended on $now ****\n"; | |
| 202 | 207 | close $LOG or die "Can't close '$LOG': $!"; | |
| 203 | 208 | } | |
| 204 | 209 | # Called when file has been deleted or moved. | |
| 205 | 210 | when ('gone') { | |
| 206 | 211 | say $LOG $fn[0] . "\n\t" . "has been (re)moved.\n"; | |
| 207 | 212 | $err{$fn[0]} = "has been (re)moved.\n"; | |
| 208 | 213 | } | |
| 209 | 214 | # Called when file has been corrupted. | |
| 210 | 215 | when ('corr') { | |
| 211 | 216 | say $LOG $fn[0] . "\n\t" . | |
| 212 | 217 | "has been corrupted.\n"; | |
| 213 | 218 | $err{$fn[0]} = "has been corrupted.\n"; | |
| 214 | 219 | } | |
| 215 | 220 | when ('diff') { | |
| 216 | 221 | say $LOG $fn[0] . "\n\t" . | |
| 217 | 222 | "doesn't match the hash in database.\n"; | |
| 218 | 223 | $err{$fn[0]} = "doesn't match the hash in database.\n"; | |
| 219 | 224 | } | |
| 220 | 225 | # Called when done, and to close the log. | |
| 221 | 226 | # If no errors occurred write "Everything is OK!" to the log. | |
| 222 | 227 | # If errors occurred print the %err hash. | |
| 223 | 228 | # Either way, print number of files processed. | |
| 224 | 229 | when ('end') { | |
| 225 | 230 | if (!%err) { | |
| 226 | 231 | say $LOG "\nEverything is OK!\n"; | |
| 227 | 232 | } else { | |
| 228 | 233 | say "\n**** Errors Occurred ****\n"; | |
| 229 | 234 | foreach my $fn (sort keys %err) { | |
| 230 | 235 | say $SE $fn . "\n\t" . $err{$fn}; | |
| 231 | 236 | } | |
| 232 | 237 | } | |
| 233 | 238 | ||
| 234 | 239 | say $LOG $n . " file(s) were tested.\n" if ($n); | |
| 235 | 240 | say $LOG "\n**** Logging ended on $now ****\n"; | |
| 236 | 241 | close $LOG or die "Can't close '$LOG': $!"; | |
| 237 | 242 | } | |
| 238 | 243 | } | |
| 239 | 244 | $semaphore->up(); | |
| 240 | 245 | } | |
| 241 | 246 | ||
| 242 | 247 | ||
| 243 | 248 | # Subroutine for reading a database file into the database hash. | |
| 244 | 249 | # This is the first subroutine that will be executed and all others | |
| 245 | 250 | # depend upon it, cause without it we don't have a | |
| 246 | 251 | # database hash to work with. | |
| 247 | 252 | sub file2hash { | |
| 248 | 253 | ||
| 249 | 254 | # The format string which is used for parsing the database file | |
| 250 | 255 | my $format = qr/^.*\t\*\t[[:alnum:]]{32}$/; | |
| 251 | 256 | my (@dbfile, @gone); | |
| 252 | 257 | ||
| 253 | 258 | # Open the database file and read it into the @dbfile variable | |
| 254 | 259 | open(MD5DB, '<', $db) or die "Can't open '$db': $!"; | |
| 255 | 260 | chomp (@dbfile = (<MD5DB>)); | |
| 256 | 261 | close(MD5DB) or die "Can't close '$db': $!"; | |
| 257 | 262 | ||
| 258 | 263 | # Loop through all the lines in the database file and split | |
| 259 | 264 | # them before storing in the database hash. | |
| 260 | 265 | # Also, print each line to STDOUT for debug purposes | |
| 261 | 266 | foreach my $line (@dbfile) { | |
| 262 | 267 | ||
| 263 | 268 | # If current line matches the proper database file format, | |
| 264 | 269 | # continue. | |
| 265 | 270 | if ($line =~ /$format/) { | |
| 266 | 271 | ||
| 267 | 272 | my ($fn, $hash) = (split(/\Q$delim/, $line)); | |
| 268 | 273 | ||
| 269 | 274 | # If $fn is a real file and not already in the hash, | |
| 270 | 275 | # continue. | |
| 271 | 276 | if (-f $fn && ! $md5h{$fn}) { | |
| 272 | 277 | $md5h{$fn} = $hash; | |
| 273 | 278 | say "$fn". "$delim" . "$hash"; | |
| 274 | 279 | ||
| 275 | 280 | # Saves the names of deleted or moved files in '@gone' | |
| 276 | 281 | # for printing at the end of this subroutine. | |
| 277 | 282 | } else { push(@gone, $fn); } | |
| 278 | 283 | } | |
| 279 | 284 | } | |
| 280 | 285 | ||
| 281 | 286 | # Clears the screen, thereby scrolling past the database file print | |
| 282 | 287 | print $clear; | |
| 283 | 288 | ||
| 284 | 289 | # Loops through the @gone array and logs every file name | |
| 285 | 290 | # that's been deleted or moved. | |
| 286 | 291 | foreach my $fn (@gone) { logger('gone', $fn); } | |
| 287 | 292 | } | |
| 288 | 293 | ||
| 289 | 294 | # Subroutine for printing the database hash to the database file | |
| 290 | 295 | sub hash2file { | |
| 291 | 296 | ||
| 292 | 297 | open(MD5DB, '>', "$db") or die "Can't open '$db': $!"; | |
| 293 | 298 | # Loops through all the keys in the database hash and prints | |
| 294 | 299 | # the entries (divided by the $delim variable) to the database file. | |
| 295 | 300 | foreach my $k (sort keys %md5h) { | |
| 296 | 301 | say MD5DB $k . $delim . $md5h{$k}; | |
| 297 | 302 | } | |
| 298 | 303 | close(MD5DB) or die "Can't close '$db': $!"; | |
| 299 | 304 | } | |
| 300 | 305 | ||
| 301 | 306 | # Subroutine for finding files | |
| 302 | 307 | # Finds all the files inside the directory name passed to it, | |
| 303 | 308 | # and sorts the output before storing it in the @files array. | |
| 304 | 309 | sub getfiles { | |
| 305 | 310 | ||
| 306 | 311 | my $dn = shift; | |
| 307 | 312 | my @files; | |
| 308 | 313 | ||
| 309 | 314 | open(FIND, '-|', qq(find -L "$dn" -type f -name "*")) | |
| 310 | 315 | or die "Can\'t run 'find': $!"; | |
| 311 | 316 | while (my $fn = (<FIND>)) { | |
| 312 | 317 | chomp($fn); | |
| 313 | 318 | $fn =~ s($dn/)(); | |
| 314 | 319 | push(@files, $fn) if (-f $fn && $fn ne basename($db)); | |
| 315 | 320 | } | |
| 316 | 321 | close(FIND) or die "Can't close 'find': $!"; | |
| 317 | 322 | return @files; | |
| 318 | 323 | } | |
| 319 | 324 | ||
| 320 | - | # Subroutine for finding and parsing *.MD5 files, adding the hashes | |
| 325 | + | sub md5double { | |
| 326 | 326 | ||
| 327 | - | my ($fn, $hash, @fields, @lines); | |
| 327 | + | if (!keys(%md5h)) { | |
| 328 | + | say "No database file. Run the script in 'index' mode first\n" . | |
| 328 | 332 | ||
| 329 | - | # The format string which is used for parsing the *.MD5 files. | |
| 333 | + | # Loop through the %md5h hash and save the checksums as keys in a | |
| 330 | - | my $format = qr/^[[:alnum:]]{32}\s\*.*/; | |
| 334 | + | # new hash called %exists. Each of those keys will hold an | |
| 331 | - | ||
| 335 | + | # anonymous array with the matching file names. | |
| 332 | - | # Loop through the @files array. | |
| 336 | + | my %exists; | |
| 333 | - | while (my $md5fn = $q->dequeue_nb()) { | |
| 337 | + | foreach my $fn (keys(%md5h)) { | |
| 338 | + | my $hash = $md5h{$fn}; | |
| 334 | 345 | ||
| 335 | - | # If the file extension is *.MD5 in either upper- or | |
| 346 | + | # Loop through the %exists hash and print files that are identical, | |
| 336 | - | # lowercase, continue. | |
| 347 | + | # if any. | |
| 337 | - | if ($md5fn =~ /.md5$/i) { | |
| 348 | + | foreach my $hash (keys(%exists)) { | |
| 349 | + | if (scalar(@{$exists{"$hash"}}) > 1) { | |
| 338 | 358 | ||
| 339 | - | # Open the *.MD5 file and read its contents to the | |
| 359 | + | # Subroutine for finding and parsing *.MD5 files, adding the hashes | |
| 340 | - | # @lines array. | |
| 360 | + | # to the database hash and thereby also to the file. | |
| 341 | - | open(MD5, '<', $md5fn) or die "Can't open '$md5fn': $!"; | |
| 361 | + | # It takes 1 argument: | |
| 342 | - | chomp(@lines = (<MD5>)); | |
| 362 | + | # (1) the thread queue | |
| 343 | - | close(MD5) or die "Can't close '$md5fn': $!"; | |
| 363 | + | sub md5import { | |
| 344 | 364 | ||
| 345 | - | # Loop to check that the format of the *.MD5 file really | |
| 365 | + | my $md5fn = shift; | |
| 348 | 366 | ||
| 349 | - | # If format string matches the line(s) in the *.MD5 | |
| 367 | + | my ($fn, $hash, @fields, @lines); | |
| 352 | 368 | ||
| 353 | - | # Split the line so that the hash and file name go | |
| 369 | + | # The format string which is used for parsing the *.MD5 files. | |
| 354 | - | # into @fields array. | |
| 370 | + | my $format = qr/^[[:alnum:]]{32}\s\*.*/; | |
| 363 | 371 | ||
| 364 | - | if ($path eq '.') { $fn = basename($fields[1]); } | |
| 372 | + | # If the file extension is *.MD5 in either upper- or | |
| 365 | - | else { $fn = dirname($md5fn) | |
| 373 | + | # lowercase, continue. | |
| 366 | - | . '/' . basename($fields[1]); } | |
| 374 | + | if ($md5fn =~ /.md5$/i) { | |
| 367 | 375 | ||
| 368 | - | # Convert CR+LF newlines to proper LF to avoid | |
| 376 | + | # Open the *.MD5 file and read its contents to the | |
| 369 | - | # identical file names from being interpreted as | |
| 377 | + | # @lines array. | |
| 370 | - | # different. | |
| 378 | + | open(MD5, '<', $md5fn) or die "Can't open '$md5fn': $!"; | |
| 371 | - | $fn =~ s/\r//; | |
| 379 | + | chomp(@lines = (<MD5>)); | |
| 380 | + | close(MD5) or die "Can't close '$md5fn': $!"; | |
| 372 | 381 | ||
| 373 | - | # Unless file name already is in the database hash, | |
| 382 | + | # Loop to check that the format of the *.MD5 file really | |
| 374 | - | # print a message, add it to the hash. | |
| 383 | + | # is correct before proceeding. | |
| 375 | - | if (! $md5h{$fn} && -f $fn) { | |
| 384 | + | foreach my $line (@lines) { | |
| 376 | 385 | ||
| 377 | - | say "$fn" . "\n\t" . | |
| 386 | + | # If format string matches the line(s) in the *.MD5 | |
| 378 | - | "Imported MD5 sum from '" . | |
| 387 | + | # file, continue. | |
| 379 | - | basename($md5fn) . | |
| 388 | + | if ($line =~ /$format/) { | |
| 381 | 389 | ||
| 382 | - | $md5h{$fn} = $hash; | |
| 390 | + | # Split the line so that the hash and file name go | |
| 391 | + | # into @fields array. | |
| 383 | 400 | ||
| 384 | - | # If file name is not a real file, write to | |
| 401 | + | if ($path eq '.') { $fn = basename($fields[1]); } | |
| 385 | - | # the log. | |
| 402 | + | else { $fn = dirname($md5fn) | |
| 386 | - | # If file name is in database hash but the | |
| 403 | + | . '/' . basename($fields[1]); } | |
| 387 | - | # MD5 sum from the MD5 file doesn't match, | |
| 404 | + | ||
| 388 | - | # print to the log. | |
| 405 | + | # Convert CR+LF newlines to proper LF to avoid | |
| 389 | - | } elsif (! -f $fn) { logger('gone', $fn); } | |
| 406 | + | # identical file names from being interpreted as | |
| 390 | - | elsif ($md5h{$fn} ne $hash) | |
| 407 | + | # different. | |
| 391 | - | { logger('diff', $md5fn); } | |
| 408 | + | $fn =~ s/\r//; | |
| 397 | 409 | ||
| 398 | - | sub md5sum { | |
| 410 | + | # Unless file name already is in the database hash, | |
| 399 | - | my $fn = shift; | |
| 411 | + | # print a message, add it to the hash. | |
| 400 | - | my $last = $parts[1]; | |
| 412 | + | if (! $md5h{$fn} && -f $fn) { | |
| 401 | 413 | ||
| 402 | - | # If $last is set it means we're dealing with a split file, so | |
| 414 | + | say "$fn" . "\n\t" . | |
| 403 | - | # set $busy to 1 for the other threads to fall asleep. We need to | |
| 415 | + | "Imported MD5 sum from '" . | |
| 404 | - | # stay in this thread when we're splitting files. So we create an | |
| 416 | + | basename($md5fn) . | |
| 405 | - | # 'until' loop which will process all the parts until the last one. | |
| 417 | + | "'.\n"; | |
| 406 | - | if ($last) { | |
| 418 | + | ||
| 407 | - | $busy = 1; | |
| 419 | + | $md5h{$fn} = $hash; | |
| 408 | - | my $md5 = Digest::MD5->new; | |
| 420 | + | ||
| 409 | - | my $done = 0; | |
| 421 | + | # If file name is not a real file, write to | |
| 410 | - | until ($done == $last) { | |
| 422 | + | # the log. | |
| 411 | - | if ($file_contents{$fn}) { | |
| 423 | + | # If file name is in database hash but the | |
| 412 | - | $md5->add($file_contents{$fn}); | |
| 424 | + | # MD5 sum from the MD5 file doesn't match, | |
| 413 | - | lock($file_stack); | |
| 425 | + | # print to the log. | |
| 414 | - | $file_stack -= length($file_contents{$fn}); | |
| 426 | + | } elsif (! -f $fn) { logger('gone', $fn); } | |
| 415 | - | lock(%file_contents); | |
| 427 | + | elsif ($md5h{$fn} ne $hash) | |
| 416 | - | delete($file_contents{$fn}); | |
| 428 | + | { logger('diff', $md5fn); } | |
| 418 | 429 | } | |
| 420 | 430 | } | |
| 421 | - | my $hash = $md5->hexdigest; | |
| 431 | + | } | |
| 431 | 432 | } | |
| 433 | + |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
kpaste.net RSS