From 835dce64ab8f77f7fda74b294390aa7b67f9d031 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 17 Sep 2020 20:00:57 -0700 Subject: [PATCH] update.sh: add unquarantine_updates function When called, the unquarantine_updates function migrates all the changes contained in the quarantine fetch area back into the main repository being careful to make sure the files end up with the correct permissions. At this point, however, it's not yet actually in use. Signed-off-by: Kyle J. McKay --- jobd/update.sh | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/jobd/update.sh b/jobd/update.sh index 80e5edc..6fda723 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -113,11 +113,90 @@ lock_update() { lockf="$_lockresult" } +# output all loose object ids, one per line, to stdout INCLUDING "/" shard separator +# look in "$1" (default "objects") +list_loose_sharded_objects() ( + cd "${1:-objects}" || return 1 + objdirs="$(echo $octet)" + [ "$objdirs" != "$octet" ] || return 0 + find -L $objdirs -mindepth 1 -maxdepth 1 -type f -name "$octet19*" -print +) + +# Migrate any and all objects/packs/ref-changes from $incoming_fetch/$incoming_objs +# Does NOT do anything with reflogs, those should already be taken care of elsewhere +unquarantine_updates() { + # just make sure everthing is copacetic first + [ -n "$incoming_fetch" ] && [ -d "$incoming_fetch" ] && + [ -n "$incoming_objs" ] && [ -d "$incoming_objs" ] || { + echo >&2 "[$proj] unquarantine failed" + exit 1 + } + _ifd="$(git --git-dir="$incoming_fetch" rev-parse --git-dir 2>/dev/null)" || : + [ -z "$_ifd" ] || _ifd="$(cd "$_ifd" && pwd -P)" + [ -n "$_ifd" ] && [ "$_ifd" = "$incoming_fetch" ] || { + echo >&2 "[$proj] unquarantine failed" + exit 1 + } + + # both $incoming_fetch and . must have all their refs packed + git --git-dir="$incoming_fetch" pack-refs --all --prune + git --git-dir=. pack-refs --all --prune + + # now every loose object and pack must be migrated out of quarantine + _objd="$(cd "$PWD/objects" && pwd -P)" + # packs first + if [ -d "$incoming_objs/pack" ]; then + if [ ! -d "$_objd/pack" ]; then + mkdir -p "$_objd/pack" + chmod "$dperms" "$_objd/pack" >/dev/null 2>&1 || : + fi + while read -r _pckf && [ -n "${_pckf%.pack}" ]; do + _pckf="${_pckf%.pack}" + rename_pack "$_pckf" "$_objd/pack/${_pckf##*/}" + chmod "$fperms" "$_objd/pack/${_pckf##*/}".?* >/dev/null 2>&1 || : + done </dev/null 2>&1 || : + fi + ln "$incoming_objs/$_objf" "$_objd/$_objf" >/dev/null 2>&1 || + dupe_file "$incoming_objs/$_objf" "$_objd/$_objf" "tmp_obj_" >/dev/null 2>&1 || + [ -f "$_objd/$_objf" ] || { + echo >&2 "[$proj] unable to unquarantine object $_objf" + exit 1 + } + chmod "$fperms" "$_objd/$_objf" >/dev/null 2>&1 || : + rm -f "$incoming_objs/$_objf" + done || exit 1 + + # now the refs + # simply replace the packed-refs file + # but do it atomically and make sure it's on the same file system first + rm -f "$PWD/packed-refs.$$" + cat "$incoming_fetch/packed-refs" >"$PWD/packed-refs.$$" + mv -f "$PWD/packed-refs.$$" "$PWD/packed-refs" + rm -f "$PWD/packed-refs.$$" +} + [ -n "$cfg_mirror" ] || { echo "Mirroring is disabled" >&2; exit 0; } -umask 002 -dperms=2775 -[ "$cfg_permission_control" != "Hooks" ] || { umask 000; dperms=2777; } +if [ "$cfg_permission_control" != "Hooks" ]; then + umask 002 + fperms=0664 + dperms=2775 +else + umask 000 + fperms=0666 + dperms=2777 +fi clean_git_env proj="${1%.git}" -- 2.11.4.GIT