]> arthur.barton.de Git - bup.git/commitdiff
save/index/drecurse: correct handling for fifos and nonexistent paths.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 21 Mar 2010 05:47:24 +0000 (01:47 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 21 Mar 2010 05:50:22 +0000 (01:50 -0400)
When indexing a fifo, you can try to open it (for security reasons) but it
has to be O_NDELAY just in case the fifo doesn't have anyone on the other
end; otherwise indexing can freeze.

In index.reduce_paths(), we weren't reporting ENOENT for reasons I can no
longer remember, but I think they must have been wrong.  Obviously if
someone specifies a nonexistent path on the command line, we should barf
rather than silently not back it up.

Add some unit tests to catch both cases.

lib/bup/drecurse.py
lib/bup/index.py
t/test.sh

index c3daaa8be0a126003e3c34cf020176c1a99fcf69..a5fddaf7e45bef970624ceea115f4ebb734195a1 100644 (file)
@@ -13,7 +13,8 @@ except AttributeError:
 class OsFile:
     def __init__(self, path):
         self.fd = None
-        self.fd = os.open(path, os.O_RDONLY|O_LARGEFILE|os.O_NOFOLLOW)
+        self.fd = os.open(path, 
+                          os.O_RDONLY|O_LARGEFILE|os.O_NOFOLLOW|os.O_NDELAY)
         
     def __del__(self):
         if self.fd:
index 1c555d7f38929d4405e2178fc5a82805888e83a0..33c286cb6471b94ba292a87aaf0f30b5cc825811 100644 (file)
@@ -393,14 +393,10 @@ def reduce_paths(paths):
     xpaths = []
     for p in paths:
         rp = realpath(p)
-        try:
-            st = os.lstat(rp)
-            if stat.S_ISDIR(st.st_mode):
-                rp = slashappend(rp)
-                p = slashappend(p)
-        except OSError, e:
-            if e.errno != errno.ENOENT:
-                raise
+        st = os.lstat(rp)
+        if stat.S_ISDIR(st.st_mode):
+            rp = slashappend(rp)
+            p = slashappend(p)
         xpaths.append((rp, p))
     xpaths.sort()
 
index 512ddb6455c3c93853e07b29f67468dac8097f9a..007f74512d39908eef6fd97faca17c84a9a1548e 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -81,6 +81,20 @@ a
 ./"
 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
 
+WVFAIL bup save -t $D/doesnt-exist-filename
+
+mv $BUP_DIR/bupindex $BUP_DIR/bi.old
+WVFAIL bup save -t $D/d/e/fifotest
+mkfifo $D/d/e/fifotest
+WVPASS bup index -u $D/d/e/fifotest
+WVFAIL bup save -t $D/d/e/fifotest
+WVFAIL bup save -t $D/d/e
+rm -f $D/d/e/fifotest
+WVPASS bup index -u $D/d/e
+WVFAIL bup save -t $D/d/e/fifotest
+mv $BUP_DIR/bi.old $BUP_DIR/bupindex
+
+WVPASS bup index -u $D/d/e
 WVPASS bup save -t $D/d/e
 WVPASSEQ "$(cd $D && bup index -m)" \
 "f