From: Jacob Bachmeyer Date: Sat, 15 Oct 2022 03:11:22 +0000 (-0500) Subject: Check timestamps while scanning directory in scan_incoming X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b469367ac142e0184c5a52b972b52ae6354b7890;p=gatekeeper.git Check timestamps while scanning directory in scan_incoming Recent files are now filtered out very early, before checking if they are open; the testsuite is adjusted accordingly. --- diff --git a/gatekeeper.pl b/gatekeeper.pl index 74eea2e..7ef1d53 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -859,6 +859,7 @@ sub scan_incoming { local *_; + my $time_bar = time - 120; my @trash; my %possible; # Get list of all possible files from incoming dir. @@ -879,6 +880,18 @@ sub scan_incoming { my $ent = $1; # if we get here, $RE_filename_here matched above # $_ remains tainted, but $ent is an untainted (and safe) copy + # Do not consider files that have been modified in the last 2 minutes. + # This is an extra safety check to avoid trying to process files that + # are still being uploaded. + if (TSTAMPCHECK) { + if ((stat($ent))[9] >= $time_bar) { + ftp_syslog('debug', "DEBUG: " + ."$ent has been modified in the last 2 minutes, skipping") + if DEBUG; + next ENT + } + } + ftp_syslog('debug', "DEBUG: uploaded file to check: $ent") if DEBUG; $possible{$ent} = 1; } @@ -931,22 +944,6 @@ sub scan_incoming { or ftp_die("FATAL: cannot exec lsof: $!"); } - # Do not consider files that have been modified in the last 2 minutes - # This is an extra safety check to avoid trying to process files that are - # still being uploaded. - if (TSTAMPCHECK) { - for my $ent (keys %possible) { - my @stat = stat($ent); - if ($stat[9] >= time - 120) { - ftp_syslog('debug', "DEBUG: " - ."$ent has been modified in the last 2 minutes, skipping") - if DEBUG; - delete ($possible{$ent}); - next; - } - } - } - my @ret; # For each remaining possibility, do some more checks diff --git a/testsuite/gatekeeper.all/00_idle.exp b/testsuite/gatekeeper.all/00_idle.exp index 3b4df0c..8f23bf6 100644 --- a/testsuite/gatekeeper.all/00_idle.exp +++ b/testsuite/gatekeeper.all/00_idle.exp @@ -84,7 +84,8 @@ analyze_log $tenv "idle processing: bogus files" { scan,bogus1 "scan found file: bogus1" scan,bogus2 "scan found file: bogus2" - scan,bogus3 "scan found file: bogus3" + + recent,bogus3 "skipped recent file: bogus3" scan,_bogus "scan found file: _bogus" scan,+bogus "scan found file: +bogus" @@ -104,8 +105,6 @@ analyze_log $tenv "idle processing: bogus files" { !scan,x?x "ignored file: x?x" !scan,;xax "ignored file: ;xax" - recent,bogus3 "skipped recent file: bogus3" - consider,bogus1 "considered file: bogus1" consider,bogus2 "considered file: bogus2" } @@ -282,10 +281,6 @@ proc check_recent_upload { recent_directive recent_main recent_signature } { set msglist { start "ftp-upload start message" nowork "ftp-upload 'nothing to do' message" - - scan,recent.bin "scan found main file" - scan,recent.bin.sig "scan found signature file" - scan,recent.bin.directive.asc "scan found directive file" } set testcase { @@ -301,6 +296,8 @@ proc check_recent_upload { recent_directive recent_main recent_signature } { lappend msglist recent,recent.bin.directive.asc \ "skipped recent directive file" } else { + lappend msglist scan,recent.bin.directive.asc \ + "scan found directive file" lappend msglist consider,recent.bin.directive.asc \ "considered directive file" } @@ -308,12 +305,14 @@ proc check_recent_upload { recent_directive recent_main recent_signature } { lappend testcase file-mtime "15 seconds ago" lappend msglist recent,recent.bin "skipped recent main file" } else { + lappend msglist scan,recent.bin "scan found main file" lappend msglist consider,recent.bin "considered main file" } if { $recent_signature } { lappend testcase fsig-mtime "15 seconds ago" lappend msglist recent,recent.bin.sig "skipped recent signature file" } else { + lappend msglist scan,recent.bin.sig "scan found signature file" lappend msglist consider,recent.bin.sig "considered signature file" }