From a010a9f4a061acad3996bc43cf25bbf6c21d4223 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 19 Aug 2022 05:16:46 -0400 Subject: [PATCH] launcher: initialize repo in a temp dir In case something goes wrong in the initial setup of the repo dir, clone it into a temporary .repo/repo.tmp/ directory first, and then rename it only when things have finished fully. Bug: https://crbug.com/gerrit/13526 Change-Id: Ib0f5a975e4d436b0fb616fac70f5789c4e02a61a Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/343537 Reviewed-by: LaMont Jones Tested-by: Mike Frysinger --- repo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/repo b/repo index e97cdd7d..c40e8add 100755 --- a/repo +++ b/repo @@ -615,7 +615,9 @@ def _Init(args, gitc_init=False): try: if not opt.quiet: print('Downloading Repo source from', url) - dst = os.path.abspath(os.path.join(repodir, S_repo)) + dst_final = os.path.abspath(os.path.join(repodir, S_repo)) + dst = dst_final + '.tmp' + shutil.rmtree(dst, ignore_errors=True) _Clone(url, dst, opt.clone_bundle, opt.quiet, opt.verbose) remote_ref, rev = check_repo_rev(dst, rev, opt.repo_verify, quiet=opt.quiet) @@ -625,6 +627,8 @@ def _Init(args, gitc_init=False): print("warning: '%s' does not look like a git-repo repository, is " "REPO_URL set correctly?" % url, file=sys.stderr) + os.rename(dst, dst_final) + except CloneFailure: print('fatal: double check your --repo-rev setting.', file=sys.stderr) if opt.quiet: @@ -1320,6 +1324,7 @@ def main(orig_args): print("fatal: cloning the git-repo repository failed, will remove " "'%s' " % path, file=sys.stderr) shutil.rmtree(path, ignore_errors=True) + shutil.rmtree(path + '.tmp', ignore_errors=True) sys.exit(1) repo_main, rel_repo_dir = _FindRepo() else: