aboutsummaryrefslogtreecommitdiff
path: root/gitosis/serve.py
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-11-15 20:56:15 +0200
committerTommi Virtanen <tv@eagain.net>2007-11-15 20:56:15 +0200
commita2e54704265b58abaa7a6edd0b64548974c69334 (patch)
treea78c9bc4e54cba195a12805917217ecce1ed3aca /gitosis/serve.py
parentFix copy-paste that made gitosis.gitweb use wrong logger. (diff)
downloadgitosis-dakkar-a2e54704265b58abaa7a6edd0b64548974c69334.tar.gz
gitosis-dakkar-a2e54704265b58abaa7a6edd0b64548974c69334.tar.bz2
gitosis-dakkar-a2e54704265b58abaa7a6edd0b64548974c69334.zip
Create leading directories when creating missing repos in gitosis-serve.
Creation is in gitosis.serve and not directly in repository.init(), because that's the location that can tell what part of the directory tree is allowed to be missing. Made the reconstructed git command include the extension as that was easier to do. haveAccess return value is now tuple, to preserve information on what parts of the path can be missing.
Diffstat (limited to 'gitosis/serve.py')
-rw-r--r--gitosis/serve.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/gitosis/serve.py b/gitosis/serve.py
index 8ada5d3..e781dea 100644
--- a/gitosis/serve.py
+++ b/gitosis/serve.py
@@ -11,6 +11,7 @@ import sys, os, re
from gitosis import access
from gitosis import repository
from gitosis import app
+from gitosis import util
ALLOW_RE = re.compile("^'(?P<path>[a-zA-Z0-9][a-zA-Z0-9@._-]*(/[a-zA-Z0-9][a-zA-Z0-9@._-]*)*)'$")
@@ -93,20 +94,29 @@ def serve(
# didn't have write access and tried to write
raise WriteAccessDenied()
- assert not newpath.endswith('.git'), \
- 'git extension should have been stripped: %r' % newpath
- repopath = '%s.git' % newpath
- if (not os.path.exists(repopath)
+ (topdir, relpath) = newpath
+ assert not relpath.endswith('.git'), \
+ 'git extension should have been stripped: %r' % relpath
+ repopath = '%s.git' % relpath
+ fullpath = os.path.join(topdir, repopath)
+ if (not os.path.exists(fullpath)
and verb in COMMANDS_WRITE):
# it doesn't exist on the filesystem, but the configuration
# refers to it, we're serving a write request, and the user is
# authorized to do that: create the repository on the fly
- repository.init(path=repopath)
+
+ # create leading directories
+ p = topdir
+ for segment in repopath.split(os.sep)[:-1]:
+ p = os.path.join(p, segment)
+ util.mkdir(p, 0750)
+
+ repository.init(path=fullpath)
# put the verb back together with the new path
- newcmd = "%(verb)s '%(newpath)s'" % dict(
+ newcmd = "%(verb)s '%(path)s'" % dict(
verb=verb,
- newpath=newpath,
+ path=fullpath,
)
return newcmd