diff options
author | Daniel Neus <[email protected]> | 2015-12-10 22:19:09 +0100 |
---|---|---|
committer | Daniel Neus <[email protected]> | 2015-12-10 22:19:09 +0100 |
commit | 86630976bbb1442750177f4c3c392eab5c65db98 (patch) | |
tree | c7ddeb6b8d23c95896fece03f95f8149a83d83eb | |
parent | 79a51627ee11f4d7f55d589751b30463d1f02a76 (diff) |
make shutil.rmtree and os.makedirs more robust (at least on windows)
-rwxr-xr-x | configure.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/configure.py b/configure.py index 8c1118cc4..6c50bb596 100755 --- a/configure.py +++ b/configure.py @@ -1942,16 +1942,41 @@ def main(argv = None): # Now begin the actual IO to setup the build + def robust_rmtree(path, max_retries=5): + for i in range(max_retries): + try: + shutil.rmtree(path) + return + except OSError, e: + time.sleep(i) + + # Final attempt, pass any Exceptions up to caller. + shutil.rmtree(path) + + def robust_makedirs(dir, max_retries=5): + for i in range(max_retries): + try: + os.makedirs(dir) + return + except OSError, e: + if e.errno == errno.EEXIST: + return + else: + time.sleep(i) + + # Final attempt, pass any Exceptions up to caller. + os.makedirs(dir) + try: if options.clean_build_tree: - shutil.rmtree(build_config.build_dir) + robust_rmtree(build_config.build_dir) except OSError as e: if e.errno != errno.ENOENT: logging.error('Problem while removing build dir: %s' % (e)) for dir in build_config.build_dirs: try: - os.makedirs(dir) + robust_makedirs(dir) except OSError as e: if e.errno != errno.EEXIST: logging.error('Error while creating "%s": %s' % (dir, e)) |