Check for duplicate names when saving a tree, and when duplicates are
found, issue a deferred error, keep the first, and ignore the rest.
Duplicates/collisions can be introduced by the strip/graft options.
For example, given:
/x/1
/y/1
consider this command:
bup save --strip /x /y
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
[metadata_f],
keep_boundaries=False)
shalist.append((mode, '.bupm', id))
- tree = force_tree or w.new_tree(shalist)
+ # FIXME: only test if collision is possible (i.e. given --strip, etc.)?
+ if force_tree:
+ tree = force_tree
+ else:
+ names_seen = set()
+ clean_list = []
+ for x in shalist:
+ name = x[1]
+ if name in names_seen:
+ parent_path = '/'.join(parts) + '/'
+ add_error('error: ignoring duplicate path %r in %r'
+ % (name, parent_path))
+ else:
+ names_seen.add(name)
+ clean_list.append(x)
+ tree = w.new_tree(clean_list)
if shalists:
shalists[-1].append((GIT_MODE_TREE,
git.mangle_name(part,
# FIXME: Not tested for now -- will require cleverness, or caution as root.
+WVSTART "save collision"
+WVPASS force-delete "$BUP_DIR" src restore
+WVPASS bup init
+WVPASS mkdir -p src/x/1 src/y/1
+WVPASS bup index -u src
+WVFAIL bup save --strip -n foo src/x src/y 2> tmp-err.log
+WVPASS grep -F "error: ignoring duplicate path '1' in '/'" tmp-err.log
+
+
WVPASS rm -rf "$tmpdir"