Module: tools Branch: master Commit: cc218ea2c267f2aee508b5d9ed26a9886b29302f URL: http://source.winehq.org/git/tools.git/?a=commit;h=cc218ea2c267f2aee508b5d9e...
Author: Francois Gouget fgouget@codeweavers.com Date: Wed May 21 16:21:36 2014 +0200
testbot/Janitor: Check and clean up the staging directory.
Purge unsubmitted jobs (web/Submit.pl) as soon as they are a day old. There should be no file older than $JobPurgeDays. Report them so they are investigated and delete them after a 7 days grace period. Detect unknown files and report them so their source can be investigated.
---
testbot/bin/Janitor.pl | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/testbot/bin/Janitor.pl b/testbot/bin/Janitor.pl index b195dff..24b2b28 100755 --- a/testbot/bin/Janitor.pl +++ b/testbot/bin/Janitor.pl @@ -214,3 +214,54 @@ if (%DeletedUsers or %DeletedVMs) } } } + +# Check the content of the staging directory +if (opendir(my $dh, "$DataDir/staging")) +{ + # We will be deleting files so read the directory in one go + my @Entries = readdir($dh); + close($dh); + foreach my $Entry (@Entries) + { + next if ($Entry eq "." or $Entry eq ".."); + $Entry =~ m%^([^/]+)$%; + my $FileName = "$DataDir/staging/$1"; + my $Age = int((-M $FileName) + 0.5); + + if ($Entry =~ /^[0-9a-f]{32}-websubmit_/) + { + if ($Age >= 1 and !unlink $FileName) + { + # The user abandonned the submit procedure half-way + LogMsg "Could not delete '$FileName': $!\n" if (!unlink($FileName)); + } + } + else + { + if ($Entry !~ /^[0-9a-f]{32}_(?:patch|patch.diff|wine-patches|winetest(?:64)?-latest.exe|work)$/) + { + LogMsg "Found a suspicious staging file: $Entry\n"; + } + + if ($JobPurgeDays != 0) + { + if ($Age >= $JobPurgeDays + 7) + { + if ((-d $FileName and !rmtree($FileName)) or + !unlink($FileName)) + { + LogMsg "Could not delete '$FileName': $!\n"; + } + } + elsif ($Age > $JobPurgeDays) + { + LogMsg "'$FileName' is $Age days old and should have been deleted already. It will be deleted in ", $JobPurgeDays + 7 - $Age, " day(s).\n"; + } + } + } + } +} +else +{ + LogMsg "0Unable to open '$DataDir/staging': $!"; +}