The index command currently clobbers the hash of a file when
marking it as valid, but the man page states:
--fake-valid
mark specified paths as up-to-date even if they aren't.
This can be useful for testing, or to avoid unnecessarily
backing up files that you know are boring.
The latter part ("avoid unnecessarily backing up [...]") cannot be
implemented with --fake-valid as is, because of the clobbering of
the hash: the fake invented hash will not exist in the repository,
and thus save checks and saves the file.
Fix this by clobbering the hash only if it's the invalid EMPTY_SHA.
Add a test for this to test-save-smaller, just because that's where
we discovered it.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
need_repack = True
if not (rig.cur.flags & index.IX_HASHVALID):
if fake_hash:
- rig.cur.gitmode, rig.cur.sha = fake_hash(path)
+ if rig.cur.sha == index.EMPTY_SHA:
+ rig.cur.gitmode, rig.cur.sha = fake_hash(path)
rig.cur.flags |= index.IX_HASHVALID
need_repack = True
if opt.fake_invalid:
# and not the new one either
WVFAIL test -f "$tmpdir/restore2/big2"
+WVSTART "index --fake-valid / save"
+WVPASS echo bigbigbigbigbig02 > "$tmpdir/save/big1"
+WVPASS echo bigbigbigbigbig03 > "$tmpdir/save/big2"
+WVPASS bup index "$tmpdir/save"
+WVPASS bup index --fake-valid "$tmpdir/save/big1" "$tmpdir/save/big2"
+WVPASS bup save -vv -n test "$tmpdir/save"
+WVPASS mkdir "$tmpdir/restore3"
+WVPASS bup restore -v --outdir="$tmpdir/restore3/" "/test/latest$tmpdir/save/"
+WVPASS cmp "$tmpdir/restore3/small" "$tmpdir/save/small"
+WVPASSEQ "$(sha1sum < "$tmpdir/restore3/big1")" "$big1sha"
+WVPASS cmp "$tmpdir/restore3/big2" "$tmpdir/save/big2"
+
WVPASS rm -rf "$tmpdir"