From a2e54704265b58abaa7a6edd0b64548974c69334 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Thu, 15 Nov 2007 20:56:15 +0200 Subject: 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. --- gitosis/serve.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'gitosis/serve.py') 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[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 -- cgit v1.2.3