From f4c336b7b6dffef0fbb37397213dcae6310ccfde Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 20 Feb 2014 12:48:22 -0800 Subject: [PATCH] server: Create file paths as needed Add support for non-flat source file layouts (e.g. relative paths that contain directory parts). Instead of creating the cache directory and possible per-file subdirectories separately, just create per-file directories on the fly. This simplifies the code, but means that you won't die until the first request if your server doesn't have permission to create these directories. --- package_cache/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package_cache/server.py b/package_cache/server.py index 97deb52..be34ee4 100644 --- a/package_cache/server.py +++ b/package_cache/server.py @@ -24,8 +24,6 @@ class Server (object): self.opener.addheaders = [ ('User-agent', 'Package-cache/{}'.format(__version__)), ] - if not _os.path.isdir(self.cache): - _os.makedirs(self.cache, exist_ok=True) def __call__(self, environ, start_response): try: @@ -54,6 +52,9 @@ class Server (object): path=cache_path, environ=environ, start_response=start_response) def _get_file_from_sources(self, url, path): + dirname = _os.path.dirname(path) + if not _os.path.isdir(dirname): + _os.makedirs(dirname, exist_ok=True) for i, source in enumerate(self.sources): source_url = source.rstrip('/') + url try: -- 2.26.2