]> arthur.barton.de Git - bup.git/commitdiff
Verify permissions in check_repo_or_die()
authorGabriel Filion <lelutin@gmail.com>
Mon, 21 Feb 2011 16:14:38 +0000 (11:14 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 10 Mar 2011 18:26:55 +0000 (18:26 +0000)
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 2069099e91d7253f7f5c17bae5f87071f1fe0a64..1b2e8edb22a15b7e718a3a58c895f92b3f487008 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -139,6 +139,8 @@ 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/*/*/*~ \
@@ -146,6 +148,7 @@ clean: Documentation/clean
                bup bup-* cmd/bup-* lib/bup/_version.py randomgen memtest \
                out[12] out2[tc] tags[12] tags2[tc] \
                testfs.img lib/bup/t/testfs.img
+       chmod u+rwx lib/bup/t/pybuptest.tmp
        rm -rf *.tmp t/*.tmp lib/*/*/*.tmp build lib/bup/build
        if test -e testfs; then rmdir testfs; fi
        if test -e lib/bup/t/testfs; then rmdir lib/bup/t/testfs; fi
index 3d8b9dab5c9caf29433ea904d61dcb82a3c1dc03..67a8540cf4a7f7af164d8f106a81df93091b827a 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:
-            log('error: %r is not a bup/git repository\n' % repo())
-            sys.exit(15)
+            log('error: %s\n' % e)
+            sys.exit(14)
+
+    init_repo()
 
 
 _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()