From fe9538746cb1c974c528df5f978243907dbfae1d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 2 Sep 2020 14:51:10 -0700 Subject: [PATCH] taskd/clone.sh: clean up more crud on exceeds limit failures Refactor part of the cleanup_failed_clone function into a new, internal _cleanup_failed_clone_bloat function that can be reused and which is responsible for removing any "crud" files that might potentially use a non-trivial amount of space. Call the new _cleanup_failed_clone_bloat from the cleanup_failed_clone to make it retain exactly the same semantics as before. Add a call to the new _cleanup_failed_clone_bloat function from the clear_all_objects_and_packs function so that any exceeds-limit clones immediately remove potentially bloating files at the same time they remove their objects and refs. Signed-off-by: Kyle J. McKay --- taskd/clone.sh | 70 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/taskd/clone.sh b/taskd/clone.sh index a9aad6b..94e543b 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -73,6 +73,52 @@ git_bzr_fetch() ( return $? ) +# 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 crud leftover from a previous failed clone attempt +# only files that could potentially consume a non-trivial amount +# of space are removed by this function +# refs and objects are left unchanged by this function +_cleanup_failed_clone_bloat() { + + # Any pre-existing FETCH_HEAD from a previous clone failed or not is + # now garbage to be removed + rm -f FETCH_HEAD + + # Remove any left-over svn dir from a previous failed attempt + rm -rf svn + + # Remove any left-over .darcs dirs from a previous failed attempt + rm -rf *.darcs + + # Remove any left-over repo.hg dir from a previous failed attempt + rm -rf repo.hg + + # Remove any left-over import/export/temp files from a previous failed attempt + 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 +} + clear_all_objects_and_packs() { if [ -d objects ]; then # make sure the repository is not left broken @@ -81,6 +127,7 @@ clear_all_objects_and_packs() { find -H refs objects -type f -exec rm -f '{}' + >/dev/null 2>&1 || : ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || : fi + _cleanup_failed_clone_bloat } exit_err=0 @@ -204,6 +251,9 @@ cleanup_git_svn_leftovers() { # removes all leftovers from a previous failed clone attempt cleanup_failed_clone() { + # Remove any left-over clone bloat + _cleanup_failed_clone_bloat + # Remove any left-over svn-remote.svn or remote.origin config git config --remove-section svn-remote.svn 2>/dev/null || : git config --remove-section remote.origin 2>/dev/null || : @@ -217,29 +267,9 @@ cleanup_failed_clone() { fi done - # Any pre-existing FETCH_HEAD from a previous clone failed or not is - # now garbage to be removed - rm -f FETCH_HEAD - # Remove any stale ref locks clear_stale_ref_locks - # Remove any left-over svn dir from a previous failed attempt - rm -rf svn - - # Remove any left-over .darcs dirs from a previous failed attempt - rm -rf *.darcs - - # Remove any left-over repo.hg dir from a previous failed attempt - rm -rf repo.hg - - # Remove any left-over import/export/temp files from a previous failed attempt - 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. -- 2.11.4.GIT