Chromium Code Reviews| Index: gclient_utils.py |
| diff --git a/gclient_utils.py b/gclient_utils.py |
| index 8385deb054a8b6823f13b5cfeef4816f45999304..45494dd0304fd47dee24d52975de63f962856009 100644 |
| --- a/gclient_utils.py |
| +++ b/gclient_utils.py |
| @@ -96,6 +96,31 @@ def FileWrite(filename, content, mode='w'): |
| f.write(content) |
| +def SafeRename(old, new): |
|
M-A Ruel
2013/09/18 18:36:16
Use safe_rename instead, we're slowly moving to no
karmann
2013/09/20 03:35:30
Done.
|
| + """ |
|
M-A Ruel
2013/09/18 18:36:16
"""Renames a file reliably.
karmann
2013/09/20 03:35:30
Done.
|
| + Renames a file reliably. |
| + |
| + Sometimes os.rename does not work because a dying git process keeps a handle |
| + on it for a few seconds. An exception is then thrown, which make the program |
| + give up what it was doing and remove what was deleted. |
| + The only solution is to catch the exception and try again until it works. |
| + """ |
| + count = 0 |
|
M-A Ruel
2013/09/18 18:36:16
# Roughly 10s
retries = 100
for i in range(retries
karmann
2013/09/20 03:35:30
Done.
|
| + while 1: |
| + count += 1 |
| + try: |
| + os.rename(old, new) |
| + logging.debug("Renamed %s in %s" % (old, new)) |
| + break |
| + except OSError: |
| + if count > 15: |
| + # Give up. |
| + raise |
| + # retry |
| + logging.debug("Renaming failed from %s to %s. Retrying ..." % (old, new)) |
| + time.sleep(1) |
| + |
| + |
| def rmtree(path): |
| """shutil.rmtree() on steroids. |