summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2014-03-25 11:14:59 -0400
committerDan Pasette <dan@mongodb.com>2014-06-01 10:27:47 -0400
commit2eb48801e124665a72347302534a219edb8ed674 (patch)
tree1aaa667b26aed1e5299b03c53bc102ed5410ce33
parentad9df9f23b3ff4c831ff642817bd2befb8bf4609 (diff)
downloadmongo-2eb48801e124665a72347302534a219edb8ed674.tar.gz
SERVER-10462 retry file deletes until the file is no longer being used by another process in testing on windows
(cherry picked from commit f9be10eccac4ce39ad64d84bd02916257f9a8ef6)
-rw-r--r--buildscripts/cleanbb.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/buildscripts/cleanbb.py b/buildscripts/cleanbb.py
index 3a754ddceec..fee7efdc0c1 100644
--- a/buildscripts/cleanbb.py
+++ b/buildscripts/cleanbb.py
@@ -5,7 +5,6 @@ import sys
import os, os.path
import utils
import time
-import exceptions
from optparse import OptionParser
def shouldKill( c, root=None ):
@@ -61,6 +60,22 @@ def killprocs( signal="", root=None ):
return killed
+def tryToRemove(path):
+ for _ in range(60):
+ try:
+ os.remove(path)
+ return True
+ except OSError, e:
+ errno = getattr(e, 'winerror', None)
+ # check for the access denied and file in use WindowsErrors
+ if errno in (5, 32):
+ print("os.remove(%s) failed, retrying in one second." % path)
+ time.sleep(1)
+ else:
+ raise e
+ return False
+
+
def cleanup( root , nokill ):
if nokill:
print "nokill requested, not killing anybody"
@@ -74,16 +89,9 @@ def cleanup( root , nokill ):
for ( dirpath , dirnames , filenames ) in os.walk( root , topdown=False ):
for x in filenames:
foo = dirpath + "/" + x
- print( "removing: " + foo )
- try:
- os.remove(foo)
- except exceptions.OSError, e:
- # SERVER-10462 compensate for Windows file locking race
- # We want to catch WindowsError but can't use that name on other platforms
- print(repr(e))
- print("os.remove(%s) failed, retrying once." % foo)
- time.sleep(1)
- os.remove(foo)
+ if os.path.exists(foo):
+ if not tryToRemove(foo):
+ raise Exception("Couldn't remove file '%s' after 60 seconds" % foo)
if __name__ == "__main__":
parser = OptionParser(usage="read the script")