From: Avery Pennarun Date: Fri, 18 Feb 2011 09:15:47 +0000 (-0800) Subject: cmd/midx, git.py: all else being equal, delete older midxes first. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=068be894919faf809dd430149f8b066bb0556cc1;p=packages%2Fb%2Fbup.git cmd/midx, git.py: all else being equal, delete older midxes first. Previous runs of 'bup midx -f' might have created invalid midx files with exactly the same length as a newer run. bup's "prune redundant midx" logic would quasi-randomly choose one or the other to delete (based on alphabetical order of filenames, basically) and sometimes that would be the new one, not the old one, so the 'bup midx -f' results never actually kicked in. Now if the file sizes are equal we'll use the mtime as a tie breaker; newer is better. Signed-off-by: Avery Pennarun --- diff --git a/cmd/midx-cmd.py b/cmd/midx-cmd.py index dfe346f..8e8fbca 100755 --- a/cmd/midx-cmd.py +++ b/cmd/midx-cmd.py @@ -160,9 +160,9 @@ def do_midx_dir(path): contents[mname] = [('%s/%s' % (path,i)) for i in m.idxnames] sizes[mname] = len(m) - # sort the biggest midxes first, so that we can eliminate smaller - # redundant ones that come later in the list - midxs.sort(lambda x,y: -cmp(sizes[x], sizes[y])) + # sort the biggest+newest midxes first, so that we can eliminate + # smaller (or older) redundant ones that come later in the list + midxs.sort(key=lambda ix: (-sizes[ix], -os.stat(ix).st_mtime)) for mname in midxs: any = 0 diff --git a/lib/bup/git.py b/lib/bup/git.py index ace4e4c..6db392a 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -360,7 +360,8 @@ class PackIdxList: unlink(full) else: midxl.append(mx) - midxl.sort(lambda x,y: -cmp(len(x),len(y))) + midxl.sort(key=lambda ix: + (-len(ix), -os.stat(ix.name).st_mtime)) for ix in midxl: any_needed = False for sub in ix.idxnames: diff --git a/t/test.sh b/t/test.sh index 0c523a6..7186710 100755 --- a/t/test.sh +++ b/t/test.sh @@ -148,6 +148,13 @@ WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \ $BUP_DIR/objects/pack/*.idx \ $BUP_DIR/objects/pack/*.idx WVPASS bup midx --check -a +all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx) +WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all +bup tick +WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all +WVPASS bup midx -a +WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \ + "$BUP_DIR/objects/pack/yyy.midx" WVPASS bup margin WVPASS bup split -t t/testfile2 >tags2t.tmp WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp