From: Gabriel Filion Date: Mon, 21 Feb 2011 16:14:38 +0000 (-0500) Subject: Verify permissions in check_repo_or_die() X-Git-Tag: bup-0.25-rc1~66 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=1df0bdd1ad937c8e9079bcdcb19dc68296177fac Verify permissions in check_repo_or_die() 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 --- diff --git a/Makefile b/Makefile index 2069099..1b2e8ed 100644 --- 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 diff --git a/lib/bup/git.py b/lib/bup/git.py index 3d8b9da..67a8540 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -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 diff --git a/lib/bup/t/tgit.py b/lib/bup/t/tgit.py index 6b0501c..0c2db17 100644 --- a/lib/bup/t/tgit.py +++ b/lib/bup/t/tgit.py @@ -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()