From b57e9a99739c634053daa04667674090c07e1938 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sun, 11 Jan 2015 01:49:33 +0100 Subject: [PATCH] win,test: try again if file unlink fails Now that parallel tests are enabled, the test runner spits out a ton of 'access denied' errors while running the tests. These happen because a virus scanner or the indexing service temporarily open the file after it has been updated, and the test runner tries to unlink() them at the same time. This patch resolves this issue by attempting to unlink the file until it succeeds. PR-URL: https://github.com/iojs/io.js/pull/284 Reviewed-by: Ben Noordhuis --- tools/test.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/test.py b/tools/test.py index 3414425a106385..c78599bf0699e2 100755 --- a/tools/test.py +++ b/tools/test.py @@ -41,6 +41,7 @@ import threading import utils import multiprocessing +import errno from os.path import join, dirname, abspath, basename, isdir, exists from datetime import datetime @@ -570,11 +571,18 @@ def PrintError(str): def CheckedUnlink(name): - try: - os.unlink(name) - except OSError, e: - PrintError("os.unlink() " + str(e)) - + while True: + try: + os.unlink(name) + except OSError, e: + # On Windows unlink() fails if another process (typically a virus scanner + # or the indexing service) has the file open. Those processes keep a + # file open for a short time only, so yield and try again; it'll succeed. + if sys.platform == 'win32' and e.errno == errno.EACCES: + time.sleep(0) + continue + PrintError("os.unlink() " + str(e)) + break def Execute(args, context, timeout=None, env={}): (fd_out, outname) = tempfile.mkstemp()