]> arthur.barton.de Git - bup.git/commitdiff
Verify permissions in check_repo_or_die()
authorGabriel Filion <lelutin@gmail.com>
Thu, 10 Mar 2011 20:41:54 +0000 (12:41 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 10 Mar 2011 20:57:17 +0000 (12:57 -0800)
Currently, if one doesn't have read or access permission up to
repo('objects/pack'), bup exits with the following error:

error: repo() is not a bup/git repository

(with repo() replaced with the actual path).

This is misleading, since there is possibly really a repository there
but the user can't access it.

Make git.check_repo_or_die() verify that the current user has the
permission to access repo('objects/pack'), and if not, output a
meaningful error message.

As a bonus, we get an error if the bup_dir path is not a directory.

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
Makefile
lib/bup/git.py
lib/bup/t/tgit.py

index ccbc624e095c537de4b0c1cc1f224680459d935f..2526726454c7a85de68c177d91bafde3031f471e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -138,10 +138,13 @@ import-docs: Documentation/clean
        git archive origin/html | (cd Documentation; tar -xvf -)
        git archive origin/man | (cd Documentation; tar -xvf -)
 
+# tgit.py plays with permissions on lib/bup/t/pybuptest.tmp, so we should
+# ensure that we can delete the directory before doing it.
 clean: Documentation/clean
        rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll *.exe \
                .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
                *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
                bup bup-* cmd/bup-* lib/bup/_version.py randomgen memtest \
                out[12] out2[tc] tags[12] tags2[tc]
+       chmod u+rwx lib/bup/t/pybuptest.tmp
        rm -rf *.tmp t/*.tmp lib/*/*/*.tmp build lib/bup/build
index 3d8b9dab5c9caf29433ea904d61dcb82a3c1dc03..233a2ee70e7bd6687679495d114d8e35aecabb89 100644 (file)
@@ -831,12 +831,18 @@ def check_repo_or_die(path=None):
     initializes the default repository automatically.
     """
     guess_repo(path)
-    if not os.path.isdir(repo('objects/pack/.')):
-        if repodir == home_repodir:
-            init_repo()
+    try:
+        os.stat(repo('objects/pack/.'))
+    except OSError, e:
+        if e.errno == errno.ENOENT:
+            if repodir != home_repodir:
+                log('error: %r is not a bup/git repository\n' % repo())
+                sys.exit(15)
+            else:
+                init_repo()
         else:
-            log('error: %r is not a bup/git repository\n' % repo())
-            sys.exit(15)
+            log('error: %s\n' % e)
+            sys.exit(14)
 
 
 _ver = None
index 6b0501cfb518deb63b8ed63c33805fede8755146..0c2db1770edf0262bfde0ba1461eb89b72aec610 100644 (file)
@@ -141,3 +141,25 @@ def test_long_index():
     WVPASSEQ(i.find_offset(obj3_bin), 0xff)
     os.remove(name)
 
+
+@wvtest
+def test_check_repo_or_die():
+    git.check_repo_or_die()
+    WVPASS('check_repo_or_die')  # if we reach this point the call above passed
+
+    mode = os.stat('pybuptest.tmp').st_mode
+    os.chmod('pybuptest.tmp', 0000)
+    try:
+        git.check_repo_or_die()
+    except SystemExit, e:
+        WVPASSEQ(e.code, 14)
+    else:
+        WVFAIL()
+    os.chmod('pybuptest.tmp', mode)
+
+    try:
+        git.check_repo_or_die('nonexistantbup.tmp')
+    except SystemExit, e:
+        WVPASSEQ(e.code, 15)
+    else:
+        WVFAIL()