From 44e870f80cd3b9970eb3d58d36d4904b5745ee88 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 13 Feb 2025 13:10:31 +0200 Subject: [PATCH] fix(toolkit): move to a tmp dir before deleting --- projects/fal/src/fal/toolkit/utils/download_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/projects/fal/src/fal/toolkit/utils/download_utils.py b/projects/fal/src/fal/toolkit/utils/download_utils.py index 39831c28..16f5e740 100644 --- a/projects/fal/src/fal/toolkit/utils/download_utils.py +++ b/projects/fal/src/fal/toolkit/utils/download_utils.py @@ -416,7 +416,11 @@ def clone_repository( f"Forcing re-download." ) print(f"Removing the existing repository: {local_repo_path} ") - shutil.rmtree(local_repo_path) + with TemporaryDirectory( + dir=target_dir, suffix=f"{local_repo_path.name}.tmp.old" + ) as tmp_dir: + os.rename(local_repo_path, tmp_dir) + shutil.rmtree(tmp_dir) # NOTE: using the target_dir to be able to avoid potential copies across temp fs # and target fs, and also to be able to atomically rename repo_name dir into place