]> arthur.barton.de Git - bup.git/commitdiff
save-cmd.py: don't test for meta index via access()
authorRob Browning <rlb@defaultvalue.org>
Sat, 28 Jun 2014 18:59:19 +0000 (13:59 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 28 Jun 2014 19:12:46 +0000 (14:12 -0500)
Instead just try to open the metadata index and catch any EACCES.
There may be an issue with access on Cygwin
(http://bugs.python.org/issue2528), and even if not, this approach
removes a potential race between access() and open().

Thanks to Mark J Hewitt <mjh@idnet.com> for reporting the problem and
helping track down the cause.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/save-cmd.py

index 327d36677db12526ae115986e71941e3772ac62a..8067facb872c38ffb40832d7442b7a81f3b43436 100755 (executable)
@@ -1,6 +1,8 @@
 #!/usr/bin/env python
 import sys, stat, time, math
 from cStringIO import StringIO
+from errno import EACCES
+
 from bup import hashsplit, git, options, index, client, metadata, hlinkdb
 from bup.helpers import *
 from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE, GIT_MODE_SYMLINK
@@ -185,10 +187,13 @@ def progress_report(n):
 
 indexfile = opt.indexfile or git.repo('bupindex')
 r = index.Reader(indexfile)
-if not os.access(indexfile + '.meta', os.W_OK|os.R_OK):
-    log('error: cannot access "%s"; have you run bup index?' % indexfile)
+try:
+    msr = index.MetaStoreReader(indexfile + '.meta')
+except IOError, ex:
+    if ex.errno != EACCES:
+        raise
+    log('error: cannot access %r; have you run bup index?' % indexfile)
     sys.exit(1)
-msr = index.MetaStoreReader(indexfile + '.meta')
 hlink_db = hlinkdb.HLinkDB(indexfile + '.hlink')
 
 def already_saved(ent):