]> arthur.barton.de Git - bup.git/commitdiff
save: make save tree collisions a deferred error
authorRob Browning <rlb@defaultvalue.org>
Thu, 30 Oct 2014 15:40:28 +0000 (10:40 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 31 Jan 2015 19:26:22 +0000 (13:26 -0600)
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>
cmd/save-cmd.py
t/test-save-strip-graft.sh

index 6cd142f394c987549ac4864e10759e28d49c148c..fc93408c2a5dcc61923d2f7bc18356856c4fe926 100755 (executable)
@@ -141,7 +141,22 @@ def _pop(force_tree, dir_metadata=None):
                                                    [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,
index bc5306c9356c895d6ae7a771c9e4096e08250fce..31f06ebe90058609b24bfe202e3a6f81fc099787 100755 (executable)
@@ -149,4 +149,13 @@ WVPASS compare-trees src/x/ "restore/latest/"
 # 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"