diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-12-17 13:04:20 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-01-10 12:47:02 +0100 |
commit | ecbbac78b9f17259e0198450796b341a7ce0d73c (patch) | |
tree | 571097959cf475320e481b2640679fa4e9bc25f3 /bin/just-lock.py | |
parent | 7a542b22e272f6444ddf8c811e8edfa1458e55c9 (diff) | |
download | justbuild-ecbbac78b9f17259e0198450796b341a7ce0d73c.tar.gz |
just-lock: Improve directory tree removal
Diffstat (limited to 'bin/just-lock.py')
-rwxr-xr-x | bin/just-lock.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/bin/just-lock.py b/bin/just-lock.py index 1db21f68..2ea25b8d 100755 --- a/bin/just-lock.py +++ b/bin/just-lock.py @@ -19,6 +19,7 @@ import shutil import subprocess import sys import tempfile +import time from argparse import ArgumentParser, ArgumentError from pathlib import Path @@ -101,6 +102,17 @@ def run_cmd(cmd: List[str], return result.stdout +def try_rmtree(tree: str) -> None: + """Safely remove a directory tree.""" + for _ in range(10): + try: + shutil.rmtree(tree) + return + except: + time.sleep(1.0) + fail("Failed to remove %s" % (tree, )) + + ### # Config utils ## @@ -549,7 +561,7 @@ def import_from_git(core_repos: Json, imports_entry: Json) -> Json: foreign_config, fail_context) # Clean up local fetch - shutil.rmtree(to_clean_up) + try_rmtree(to_clean_up) return core_repos |