All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: gitster@pobox.com, git@vger.kernel.org,
	Johannes.Schindelin@gmx.de, spearce@spearce.org
Subject: Re: [PATCH] Make repack less likely to corrupt repository
Date: Sun, 08 Feb 2009 22:04:46 -0800	[thread overview]
Message-ID: <7vwsc0uow1.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1234140299-29785-1-git-send-email-robin.rosenberg@dewire.com> (Robin Rosenberg's message of "Mon, 9 Feb 2009 01:44:59 +0100")

Robin Rosenberg <robin.rosenberg@dewire.com> writes:

> diff --git a/git-repack.sh b/git-repack.sh
> index 458a497..6a7ba90 100755
> --- a/git-repack.sh
> +++ b/git-repack.sh
> @@ -93,22 +93,43 @@ for name in $names ; do
>  	chmod a-w "$PACKTMP-$name.pack"
>  	chmod a-w "$PACKTMP-$name.idx"
>  	mkdir -p "$PACKDIR" || exit

> +	ok=t

This does not seem to be used at all.

> +	if test -f "$PACKDIR/pack-$name.pack"
> +	then
> +		mv -f "$PACKDIR/pack-$name.pack" \
> +			"$PACKDIR/old-pack-$name.pack"
> +	fi &&
> +	if test -f "$PACKDIR/pack-$name.idx"
> +	then
> +		mv -f "$PACKDIR/pack-$name.idx" \
> +			"$PACKDIR/old-pack-$name.idx" ||
> +		(
> +			mv -f "$PACKDIR/old-pack-$name.pack" \
> +			"$PACKDIR/pack-$name.pack" || (
> +				echo >&2 "Failed to restore after a failure to rename"\
> +					"pack-$name{pack,idx} to old-$pack{pack,idx} in $PACKDIR"
> +				echo >&2 "Please acquire advice on how to recover from this"\
> +					"situation before you proceed."
> +				exit 1
> +			) || false
> +		) || (
> +			echo >&2 "Failed to replace the existing pack with updated one."
> +			echo >&2 "We recovered from the situation, but cannot continue".
> +			echo >&2 "repacking."
> +			exit 0
> +		)
> +	fi &&
>  	mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
>  	mv -f "$PACKTMP-$name.idx"  "$PACKDIR/pack-$name.idx" &&
>  	test -f "$PACKDIR/pack-$name.pack" &&
>  	test -f "$PACKDIR/pack-$name.idx" || {
>  		echo >&2 "Couldn't replace the existing pack with updated one."
> +		if (test -f "$PACKDIR/old-pack-$name.pack" ||
> +			test -f "$PACKDIR/old-pack-$name.idx")

Why fork a subshell?

> +		then
> +			echo >&2 "The original set of packs have been saved as"
> +			echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
> +		fi
>  		exit 1

What's troubling more is that this would seem to leave the result even
more inconsistent if there are more than one packs that need to be
replaced.

I wonder if a completely different strategy would be less problematic.

 (1) create a new directory objects/new-pack/, copy ones with the same
     name, and hardlink the rest;

 (2) Do the usual "mv temp to final" dance into objects/new-pack/, but
     without any old-pack-$name part; if any fail, do not even try to
     recover but just barf, perhaps removing new-pack directory;

 (3) If all succeed, rename pack/ to old-pack/, rename new-pack/ to pack/.
     If the former fails, you can stop and report that your repack did not
     quite work, but new packs are still found in new-pack.  If the latter
     fails, you can stop and report that your repack did not quite work,
     but original packs are still found in old-pack.

 (4) If the directory rename succeed, remove old-pack/

  reply	other threads:[~2009-02-09  6:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-09  0:44 [PATCH] Make repack less likely to corrupt repository Robin Rosenberg
2009-02-09  6:04 ` Junio C Hamano [this message]
2009-02-10  7:07   ` Robin Rosenberg
2009-02-10 15:59     ` Junio C Hamano
2009-02-10 16:57       ` Robin Rosenberg
2009-02-10 20:16         ` Junio C Hamano
2009-02-10 23:51           ` Robin Rosenberg
2009-02-10 23:56             ` Junio C Hamano
2009-02-11  0:27               ` Robin Rosenberg
2009-02-11  0:31                 ` Junio C Hamano
2009-02-11 17:08                   ` Robin Rosenberg
2009-02-15 16:15                   ` Robin Rosenberg
2009-02-15 16:46                     ` Johannes Schindelin
2009-02-15 18:42                       ` Robin Rosenberg
2009-02-15 20:09                         ` Junio C Hamano
2009-02-16  5:17                           ` Robin Rosenberg
2009-02-19 22:21                           ` Robin Rosenberg
2009-02-19 22:44                             ` Johannes Schindelin
2009-02-20  0:09                               ` Junio C Hamano
2009-02-20  0:09                               ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vwsc0uow1.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.