Francois Gouget : testbot/lib: Add a utility function to atomically create a new directory.
Alexandre Julliard
julliard at winehq.org
Tue Jun 17 14:37:58 CDT 2014
Module: tools
Branch: master
Commit: 50f0f9de34bf23fcb256ad32dcf3abbdcf097bec
URL: http://source.winehq.org/git/tools.git/?a=commit;h=50f0f9de34bf23fcb256ad32dcf3abbdcf097bec
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Mon Jun 16 16:11:25 2014 +0200
testbot/lib: Add a utility function to atomically create a new directory.
It ensures there are no race conditions with other processes and simplifies the calling code.
---
testbot/bin/Engine.pl | 14 ++------------
testbot/lib/WineTestBot/Utils.pm | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/testbot/bin/Engine.pl b/testbot/bin/Engine.pl
index 29dc919..75a8851 100755
--- a/testbot/bin/Engine.pl
+++ b/testbot/bin/Engine.pl
@@ -412,12 +412,7 @@ sub HandleWinePatchMLSubmission()
my $FullMessageFileName = "$DataDir/staging/$1";
# Create a work directory
- my $WorkDir = "$DataDir/staging/" . GenerateRandomString(32) . "_work";
- while (-e $WorkDir)
- {
- $WorkDir = "$DataDir/staging/" . GenerateRandomString(32) . "_work";
- }
- mkdir $WorkDir;
+ my $WorkDir = CreateNewDir("$DataDir/staging", "_work");
# Process the patch
my $Parser = new MIME::Parser;
@@ -489,12 +484,7 @@ sub HandleWinePatchWebSubmission()
foreach my $WebPatchId (sort { $a <=> $b } @WebPatchIds)
{
# Create a working dir
- my $WorkDir = "$DataDir/staging/" . GenerateRandomString(32) . "_work";
- while (-e $WorkDir)
- {
- $WorkDir = "$DataDir/staging/" . GenerateRandomString(32) . "_work";
- }
- mkdir $WorkDir;
+ my $WorkDir = CreateNewDir("$DataDir/staging", "_work");
# Process the patch
my $Parser = new MIME::Parser;
diff --git a/testbot/lib/WineTestBot/Utils.pm b/testbot/lib/WineTestBot/Utils.pm
index 1cea5d7..743e5ee 100644
--- a/testbot/lib/WineTestBot/Utils.pm
+++ b/testbot/lib/WineTestBot/Utils.pm
@@ -33,7 +33,8 @@ use vars qw (@ISA @EXPORT);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(&MakeSecureURL &SecureConnection &GenerateRandomString
- &OpenNewFile &CreateNewFile &CreateNewLink &BuildEMailRecipient);
+ &OpenNewFile &CreateNewFile &CreateNewLink &CreateNewDir
+ &BuildEMailRecipient);
sub MakeSecureURL($)
{
@@ -105,6 +106,20 @@ sub CreateNewLink($$$)
}
}
+sub CreateNewDir($$)
+{
+ my ($Dir, $Suffix) = @_;
+
+ while (1)
+ {
+ my $Path = "$Dir/" . GenerateRandomString(32) . $Suffix;
+ return $Path if (mkdir $Path);
+
+ # This is not an error that will be fixed by trying a different path
+ return undef if (!$!{EEXIST});
+ }
+}
+
sub DateTimeToString($)
{
my ($Time) = @_;
More information about the wine-cvs
mailing list