From 600d376622f3acb0536d0d59c7edb37835cb808a Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 9 Jun 2020 19:20:14 -0700 Subject: [PATCH] taskd/clone.sh: clean up git-svn temp files A failed `git-svn` clone may leave a *lot* of temp files lying around; remove them in the `cleanup_failed_clone` function and just before retrying a fetch. Signed-off-by: Kyle J. McKay --- taskd/clone.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/taskd/clone.sh b/taskd/clone.sh index 1434e93..c3d10aa 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -109,6 +109,25 @@ EOT } | mailref "clone@$cfg_gitweburl/$proj.git" -s "[$cfg_name] $proj clone failed" "$failaddrs" || : } +# removes any git-svn leftovers +cleanup_git_svn_leftovers() { + + # Remove any stale git-svn temp files + # The git-svn process creates temp files with random 10 character names + # in the root of $GIT_DIR. Unfortunately they do not have a recognizable + # prefix, so we just have to kill any files with a 10-character name. + # All characters are chosen from + # [A-Za-z0-9_] so we can at least check that and fortunately the only + # collision is 'FETCH_HEAD' but that doesn't matter. + # There may also be temp files with a Git_ prefix as well. + _randchar='[A-Za-z0-9_]' + _randchar2="$_randchar$_randchar" + _randchar4="$_randchar2$_randchar2" + _randchar10="$_randchar4$_randchar4$_randchar2" + find -L . -maxdepth 1 -type f -name "$_randchar10" -exec rm -f '{}' + || : + find -L . -maxdepth 1 -type f -name "Git_*" -exec rm -f '{}' + || : +} + # removes all leftovers from a previous failed clone attempt cleanup_failed_clone() { @@ -142,6 +161,9 @@ cleanup_failed_clone() { rm -f bfe-marks dfe-marks hg2git-heads hg2git-mapping hg2git-marks* hg2git-state \ gfi-marks gfi-packs .pkts-temp .refs-temp + # Remove any git-svn junk + cleanup_git_svn_leftovers + # We want a gc right after the clone, so re-enable that just in case. # There's a potential race where we could add it and gc.sh could remove # it, but we'll reunset lastgc just before we remove .delaygc at the end. @@ -364,6 +386,7 @@ case "$url" in # Pause briefly before retrying to be friendly to the server echo 'Pausing for 120 seconds before retrying' sleep 120 + cleanup_git_svn_leftovers echo 'Retrying fetch' done [ "${svn_err:-1}" -eq 0 ] || svn_ret_err "$svn_err" -- 2.11.4.GIT