Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add "bup index --clear" to clear the index.

Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
  • Loading branch information...
commit 572810f33b5c6bf692b30f6669ba034f0590c571 1 parent 1870a82
@zoranzaric zoranzaric authored rlbdv committed
Showing with 52 additions and 3 deletions.
  1. +4 −1 Documentation/bup-index.md
  2. +27 −2 cmd/index-cmd.py
  3. +21 −0 t/test.sh
View
5 Documentation/bup-index.md
@@ -9,7 +9,7 @@ bup-index - print and/or update the bup filesystem index
# SYNOPSIS
bup index \<-p|-m|-s|-u\> [-H] [-l] [-x] [\--fake-valid]
-[\--fake-invalid] [\--check] [-f *indexfile*] [\--exclude *path*]
+[\--fake-invalid] [\--check] [\--clear] [-f *indexfile*] [\--exclude *path*]
[\--exclude-from *filename*] [-v] \<filenames...\>
# DESCRIPTION
@@ -138,6 +138,9 @@ does, due to the accommodations described above.
: carefully check index file integrity before and after
updating. Mostly useful for automated tests.
+\--clear
+: clear the index.
+
-f, \--indexfile=*indexfile*
: use a different index filename instead of
`~/.bup/bupindex`.
View
29 cmd/index-cmd.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import sys, stat, time, os
+import sys, stat, time, os, errno
from bup import metadata, options, git, index, drecurse, hlinkdb
from bup.helpers import *
from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE
@@ -49,6 +49,21 @@ def check_index(reader):
log('check: passed.\n')
+def clear_index(indexfile):
+ indexfiles = [indexfile, indexfile + '.meta', indexfile + '.hlink']
+ cleared = False
+ for indexfile in indexfiles:
+ path = git.repo(indexfile)
+ try:
+ os.remove(path)
+ if opt.verbose:
+ log('clear: removed %s\n' % path)
+ cleared = True
+ except OSError, e:
+ if e.errno != errno.ENOENT:
+ raise
+
+
def update_index(top, excluded_paths):
# tmax and start must be epoch nanoseconds.
tmax = (time.time() - 1) * 10**9
@@ -162,6 +177,7 @@ def hashgen(name):
s,status print each filename with a status char (A/M/D) (implies -p)
u,update recursively update the index entries for the given file/dir names (default if no mode is specified)
check carefully check index file integrity
+clear clear the index
Options:
H,hash print the hash for each object next to its name
l,long print more information about each file
@@ -176,7 +192,12 @@ def hashgen(name):
o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])
-if not (opt.modified or opt['print'] or opt.status or opt.update or opt.check):
+if not (opt.modified or \
+ opt['print'] or \
+ opt.status or \
+ opt.update or \
+ opt.check or \
+ opt.clear):
opt.update = 1
if (opt.fake_valid or opt.fake_invalid) and not opt.update:
o.fatal('--fake-{in,}valid are meaningless without -u')
@@ -199,6 +220,10 @@ def hashgen(name):
log('check: starting initial check.\n')
check_index(index.Reader(indexfile))
+if opt.clear:
+ log('clear: clearing index.\n')
+ clear_index(indexfile)
+
excluded_paths = drecurse.parse_excludes(flags)
paths = index.reduce_paths(extra)
View
21 t/test.sh
@@ -665,3 +665,24 @@ WVSTART "save disjoint top-level directories"
# For now, assume that "ls -a" and "sort" use the same order.
WVPASSEQ "$(bup ls -a src/latest)" "$(echo -e "$top_dir/\ntmp/" | sort)"
) || WVFAIL
+
+
+WVSTART "clear-index"
+D=clear-index.tmp
+export BUP_DIR="$TOP/$D/.bup"
+rm -rf $TOP/$D
+mkdir $TOP/$D
+WVPASS bup init
+touch $TOP/$D/foo
+touch $TOP/$D/bar
+bup index -u $D
+WVPASSEQ "$(bup index -p)" "$D/foo
+$D/bar
+$D/
+./"
+rm $TOP/$D/foo
+WVPASS bup index --clear
+bup index -u $TOP/$D
+WVPASSEQ "$(bup index -p)" "$D/bar
+$D/
+./"
Please sign in to comment.
Something went wrong with that request. Please try again.