# HG changeset patch # User Marcin Kuzminski # Date 2017-03-23 21:33:19 # Node ID 58195c38431ab286814452a093d3ec7c34087d36 # Parent bb8ad7ab25209e52a326b561c5785da102ec001b git-lfs: don't store oid under repo-path. - using a central store allows forks to re-use the LFS blobs diff --git a/vcsserver/git_lfs/app.py b/vcsserver/git_lfs/app.py --- a/vcsserver/git_lfs/app.py +++ b/vcsserver/git_lfs/app.py @@ -118,7 +118,7 @@ def lfs_objects_batch(request): obj_href = request.route_url('lfs_objects_oid', repo=repo, oid=oid) obj_verify_href = request.route_url('lfs_objects_verify', repo=repo) store = LFSOidStore( - repo, oid, store_location=request.registry.git_lfs_store_path) + oid, repo, store_location=request.registry.git_lfs_store_path) handler = OidHandler( store, repo, auth, oid, obj_size, obj_data, obj_href, obj_verify_href) @@ -146,7 +146,7 @@ def lfs_objects_oid_upload(request): repo = request.matchdict.get('repo') oid = request.matchdict.get('oid') store = LFSOidStore( - repo, oid, store_location=request.registry.git_lfs_store_path) + oid, repo, store_location=request.registry.git_lfs_store_path) engine = store.get_engine(mode='wb') log.debug('LFS: starting chunked write of LFS oid: %s to storage', oid) with engine as f: @@ -161,7 +161,7 @@ def lfs_objects_oid_download(request): oid = request.matchdict.get('oid') store = LFSOidStore( - repo, oid, store_location=request.registry.git_lfs_store_path) + oid, repo, store_location=request.registry.git_lfs_store_path) if not store.has_oid(): log.debug('LFS: oid %s does not exists in store', oid) return write_response_error( @@ -188,8 +188,8 @@ def lfs_objects_verify(request): return write_response_error( HTTPBadRequest, 'missing oid and size in request data') - store = LFSOidStore(repo, oid, - store_location=request.registry.git_lfs_store_path) + store = LFSOidStore( + oid, repo, store_location=request.registry.git_lfs_store_path) if not store.has_oid(): log.debug('LFS: oid %s does not exists in store', oid) return write_response_error( diff --git a/vcsserver/git_lfs/lib.py b/vcsserver/git_lfs/lib.py --- a/vcsserver/git_lfs/lib.py +++ b/vcsserver/git_lfs/lib.py @@ -106,11 +106,10 @@ class OidHandler(object): class LFSOidStore(object): - def __init__(self, repo, oid, store_location=None): - self._store = store_location or self.get_default_store() + def __init__(self, oid, repo, store_location=None): self.oid = oid self.repo = repo - self.store_path = os.path.join(self._store, repo) + self.store_path = store_location or self.get_default_store() self.tmp_oid_path = os.path.join(self.store_path, oid + '.tmp') self.oid_path = os.path.join(self.store_path, oid) self.fd = None @@ -164,4 +163,4 @@ class LFSOidStore(object): oid = os.path.join(self.store_path, self.oid) size = os.stat(oid).st_size - return size \ No newline at end of file + return size diff --git a/vcsserver/git_lfs/tests/test_lfs_app.py b/vcsserver/git_lfs/tests/test_lfs_app.py --- a/vcsserver/git_lfs/tests/test_lfs_app.py +++ b/vcsserver/git_lfs/tests/test_lfs_app.py @@ -106,8 +106,9 @@ class TestLFSApplication(object): def test_app_batch_api_download(self, git_lfs_app, http_auth): oid = '456' - oid_path = os.path.join(git_lfs_app._store, 'repo', oid) - os.makedirs(os.path.dirname(oid_path)) + oid_path = os.path.join(git_lfs_app._store, oid) + if not os.path.isdir(os.path.dirname(oid_path)): + os.makedirs(os.path.dirname(oid_path)) with open(oid_path, 'wb') as f: f.write('OID_CONTENT') @@ -172,8 +173,9 @@ class TestLFSApplication(object): def test_app_verify_api_size_mismatch(self, git_lfs_app): oid = 'existing' - oid_path = os.path.join(git_lfs_app._store, 'repo', oid) - os.makedirs(os.path.dirname(oid_path)) + oid_path = os.path.join(git_lfs_app._store, oid) + if not os.path.isdir(os.path.dirname(oid_path)): + os.makedirs(os.path.dirname(oid_path)) with open(oid_path, 'wb') as f: f.write('OID_CONTENT') @@ -187,8 +189,9 @@ class TestLFSApplication(object): def test_app_verify_api(self, git_lfs_app): oid = 'existing' - oid_path = os.path.join(git_lfs_app._store, 'repo', oid) - os.makedirs(os.path.dirname(oid_path)) + oid_path = os.path.join(git_lfs_app._store, oid) + if not os.path.isdir(os.path.dirname(oid_path)): + os.makedirs(os.path.dirname(oid_path)) with open(oid_path, 'wb') as f: f.write('OID_CONTENT') @@ -210,8 +213,9 @@ class TestLFSApplication(object): def test_app_download_api(self, git_lfs_app): oid = 'existing' - oid_path = os.path.join(git_lfs_app._store, 'repo', oid) - os.makedirs(os.path.dirname(oid_path)) + oid_path = os.path.join(git_lfs_app._store, oid) + if not os.path.isdir(os.path.dirname(oid_path)): + os.makedirs(os.path.dirname(oid_path)) with open(oid_path, 'wb') as f: f.write('OID_CONTENT') @@ -228,6 +232,6 @@ class TestLFSApplication(object): assert response.json == {u'upload': u'ok'} # verify that we actually wrote that OID - oid_path = os.path.join(git_lfs_app._store, 'repo', oid) + oid_path = os.path.join(git_lfs_app._store, oid) assert os.path.isfile(oid_path) assert 'CONTENT' == open(oid_path).read() diff --git a/vcsserver/git_lfs/tests/test_lib.py b/vcsserver/git_lfs/tests/test_lib.py --- a/vcsserver/git_lfs/tests/test_lib.py +++ b/vcsserver/git_lfs/tests/test_lib.py @@ -24,7 +24,7 @@ from vcsserver.git_lfs.lib import OidHan def lfs_store(tmpdir): repo = 'test' oid = '123456789' - store = LFSOidStore(repo=repo, oid=oid, store_location=str(tmpdir)) + store = LFSOidStore(oid=oid, repo=repo, store_location=str(tmpdir)) return store @@ -66,8 +66,9 @@ class TestOidHandler(object): def test_download_oid(self, oid_handler): store = oid_handler.get_store() + if not os.path.isdir(os.path.dirname(store.oid_path)): + os.makedirs(os.path.dirname(store.oid_path)) - os.makedirs(os.path.dirname(store.oid_path)) with open(store.oid_path, 'wb') as f: f.write('CONTENT') @@ -81,8 +82,9 @@ class TestOidHandler(object): def test_upload_oid_that_exists(self, oid_handler): store = oid_handler.get_store() + if not os.path.isdir(os.path.dirname(store.oid_path)): + os.makedirs(os.path.dirname(store.oid_path)) - os.makedirs(os.path.dirname(store.oid_path)) with open(store.oid_path, 'wb') as f: f.write('CONTENT')