From f4545126197781beb03bb0fd47e7f24ce5af6ca8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 11 Nov 2019 04:34:16 -0500 Subject: sync: make .git init more robust Hitting Ctrl-C in the middle of this func will leave the .git in a bad state that requires manual recovery. The code tries to catch all exceptions and recover by deleting the incomplete .git dir, but it omits KeyboardInterrupt which Exception misses. We could add that to the recovery path, but we can make this more robust with a different approach: set up everything in .git.tmp/ and only move it to .git/ once we've fully initialized it. Change-Id: I0f5b97f2e19fc39cffc3e5e23993a2da7220f4e3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/244733 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- platform_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'platform_utils.py') diff --git a/platform_utils.py b/platform_utils.py index 77e8fdf..6684ebc 100644 --- a/platform_utils.py +++ b/platform_utils.py @@ -241,14 +241,15 @@ def _makelongpath(path): return path -def rmtree(path): +def rmtree(path, ignore_errors=False): """shutil.rmtree(path) wrapper with support for long paths on Windows. Availability: Unix, Windows.""" + onerror = None if isWindows(): - shutil.rmtree(_makelongpath(path), onerror=handle_rmtree_error) - else: - shutil.rmtree(path) + path = _makelongpath(path) + onerror = handle_rmtree_error + shutil.rmtree(path, ignore_errors=ignore_errors, onerror=onerror) def handle_rmtree_error(function, path, excinfo): -- cgit v1.2.3