From a408ebb98b3fbf7b766f93ee20456e830deef23e Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 21 Mar 2010 01:47:24 -0400 Subject: [PATCH] save/index/drecurse: correct handling for fifos and nonexistent paths. 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 | 3 ++- lib/bup/index.py | 12 ++++-------- t/test.sh | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py index c3daaa8..a5fddaf 100644 --- a/lib/bup/drecurse.py +++ b/lib/bup/drecurse.py @@ -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: diff --git a/lib/bup/index.py b/lib/bup/index.py index 1c555d7..33c286c 100644 --- a/lib/bup/index.py +++ b/lib/bup/index.py @@ -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() diff --git a/t/test.sh b/t/test.sh index 512ddb6..007f745 100755 --- 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 -- 2.39.2