From ccc3d8edee0c722106c65d7ee34408d68d25481f Mon Sep 17 00:00:00 2001 From: Daniel <86781586+0xDS@users.noreply.github.com> Date: Mon, 13 Jan 2025 02:10:24 +1400 Subject: [PATCH] Update launch_utils.py Updated the cloning logic to first clone into a temporary directory and move it to the final destination only if the operation succeeds. --- modules/launch_utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/launch_utils.py b/modules/launch_utils.py index 1aceb0dbf4e..4e32172b2ea 100644 --- a/modules/launch_utils.py +++ b/modules/launch_utils.py @@ -167,7 +167,8 @@ def run_git(dir, name, command, desc=None, errdesc=None, custom_env=None, live: def git_clone(url, dir, name, commithash=None): - # TODO clone into temporary dir and move if successful + # Clone into a temporary directory + temp_dir = dir + "_temp" if os.path.exists(dir): if commithash is None: @@ -187,9 +188,10 @@ def git_clone(url, dir, name, commithash=None): return try: - run(f'"{git}" clone --config core.filemode=false "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True) + run(f'"{git}" clone --config core.filemode=false "{url}" "{temp_dir}"', f"Cloning {name} into {temp_dir}...", f"Couldn't clone {name}", live=True) + shutil.move(temp_dir, dir) # Move temp directory to final directory except RuntimeError: - shutil.rmtree(dir, ignore_errors=True) + shutil.rmtree(temp_dir, ignore_errors=True) raise if commithash is not None: