From: Rob Browning Date: Sun, 25 Aug 2013 22:33:42 +0000 (-0500) Subject: save-cmd.py: don't write an irrelevant and incomplete .bupm fragment. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=46dae41b4bdfeb55aa00c34f92fe9cf514a3b809;p=packages%2Fb%2Fbup.git save-cmd.py: don't write an irrelevant and incomplete .bupm fragment. When finishing up (leaving) a directory and preparing to store its related tree in the repository, don't write the pending .bupm (which is still incomplete) to the pack if we know the directory already exists in the repository (i.e. when we're not going to write it either). This problem was discovered when Zoran noticed that two consecutive saves without an intervening index could produce a repository with an unreferenced blob (according to git fsck). Reported-by: Zoran Zaric Signed-off-by: Rob Browning --- diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index 66d56e2..5031edb 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -124,7 +124,7 @@ def _pop(force_tree, dir_metadata=None): part = parts.pop() shalist = shalists.pop() metalist = metalists.pop() - if metalist: + if metalist and not force_tree: if dir_metadata: # Override the original metadata pushed for this dir. metalist = [('', dir_metadata)] + metalist[1:] sorted_metalist = sorted(metalist, key = lambda x : x[0]) diff --git a/t/test-save-creates-no-unrefs.sh b/t/test-save-creates-no-unrefs.sh new file mode 100755 index 0000000..229da4c --- /dev/null +++ b/t/test-save-creates-no-unrefs.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +. ./wvtest-bup.sh + +set -eo pipefail + +WVSTART 'all' + +top="$(pwd)" +tmpdir="$(wvmktempdir)" +export BUP_DIR="$tmpdir/bup" +export GIT_DIR="$BUP_DIR" + +bup() { "$top/bup" "$@"; } + +mkdir -p "$tmpdir/src" +touch "$tmpdir/src/foo" +bup init +bup index "$tmpdir/src" +bup save -n src "$tmpdir/src" +WVPASSEQ "$(git fsck --unreachable)" "" +bup save -n src "$tmpdir/src" +WVPASSEQ "$(git fsck --unreachable)" "" + +rm -rf "$tmpdir"