dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00405
[PATCH v3 2/4] web: move url-to-path step into get_named_file
Let repo implementations decide on '/'-to-os.path.sep replacements. Such
replacements don't make sense for memory-based repos, especially on
Windows, where os.path.sep differs from '/'.
This fixes test_get_idx_file and test_get_pack_file in
test_web.DumbHandlersTestCase on Windows.
---
Changed from v2: took Dave's suggestion and moved the '/' substitution
into the Repo implementation of get_named_file().
dulwich/repo.py | 3 ++-
dulwich/web.py | 10 +++-------
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/dulwich/repo.py b/dulwich/repo.py
index 0646885..d5d8713 100644
--- a/dulwich/repo.py
+++ b/dulwich/repo.py
@@ -1131,8 +1131,9 @@ class Repo(BaseRepo):
# TODO(dborowitz): sanitize filenames, since this is used directly by
# the dumb web serving code.
path = path.lstrip(os.path.sep)
+ path = os.path.realpath(os.path.join(self.controldir(), path))
try:
- return open(os.path.join(self.controldir(), path), 'rb')
+ return open(path, 'rb')
except (IOError, OSError), e:
if e.errno == errno.ENOENT:
return None
diff --git a/dulwich/web.py b/dulwich/web.py
index 3f354db..be66b46 100644
--- a/dulwich/web.py
+++ b/dulwich/web.py
@@ -112,13 +112,9 @@ def send_file(req, f, content_type):
raise
-def _url_to_path(url):
- return url.replace('/', os.path.sep)
-
-
def get_text_file(req, backend, mat):
req.nocache()
- path = _url_to_path(mat.group())
+ path = mat.group()
logger.info('Sending plain text file %s', path)
return send_file(req, get_repo(backend, mat).get_named_file(path),
'text/plain')
@@ -143,7 +139,7 @@ def get_loose_object(req, backend, mat):
def get_pack_file(req, backend, mat):
req.cache_forever()
- path = _url_to_path(mat.group())
+ path = mat.group()
logger.info('Sending pack file %s', path)
return send_file(req, get_repo(backend, mat).get_named_file(path),
'application/x-git-packed-objects')
@@ -151,7 +147,7 @@ def get_pack_file(req, backend, mat):
def get_idx_file(req, backend, mat):
req.cache_forever()
- path = _url_to_path(mat.group())
+ path = mat.group()
logger.info('Sending pack file %s', path)
return send_file(req, get_repo(backend, mat).get_named_file(path),
'application/x-git-packed-objects-toc')
--
1.7.3.2.msysgit.0
Follow ups
References