Skip to content
Snippets Groups Projects
Commit a3b3e494 authored by Georges Racinet's avatar Georges Racinet
Browse files

RepositoryService.CreateRepositoryFromBundle: cleanup after error

In case of error after repository creation, Gitaly makes sure to
remove the created repo. We must do the same, and it opens up
room for retries.
parent b8727a86
No related branches found
No related tags found
1 merge request!102RepositoryService.FetchBundle: initial implementation
......@@ -457,5 +457,14 @@
request, context,
first_request_handler=init_repo
) as (repo, tmpf):
unbundle(repo, tmpf.name)
try:
unbundle(repo, tmpf.name)
except Exception as exc:
internal_error(
context, no_response,
message="error in bundle application: %r" % exc)
# same cleanup as Gitaly does, which gives later
# attempts, perhaps with a better bundle, chances to
# succeed.
shutil.rmtree(repo.root)
finally:
......@@ -461,6 +470,4 @@
finally:
# TODO in case of error, we must remove the created repo,
# so that a later attempt has a chance to succeed.
# response is the same in case of success and error
return CreateRepositoryFromBundleResponse()
......
......@@ -585,6 +585,17 @@
assert exc_info.value.code() == grpc.StatusCode.INTERNAL
assert 'Too many levels of symbolic links' in exc_info.value.details()
# in case of error after repo creation, the repo must be removed
trepo_msg = Repository(relative_path='bundle-fail',
storage_name=grpc_repo.storage_name)
broken_bundle_path = tmpdir / 'broken-bundle'
broken_bundle_path.write("Obviously garbage")
with pytest.raises(grpc.RpcError) as exc_info:
fixture.create_repository_from_bundle(broken_bundle_path, trepo_msg)
assert exc_info.value.code() == grpc.StatusCode.INTERNAL
assert "bundle" in exc_info.value.details()
assert not fixture.repo_path('bundle-fail').exists()
def test_create_bundle_from_ref_list(fixture_with_repo, tmpdir):
fixture = fixture_with_repo
......
......@@ -474,3 +474,16 @@
without_repository=True)
assert exc_info_hg.value.code() == exc_info_git.value.code()
assert exc_info_hg.value.details() == exc_info_git.value.details()
# test error case: error in bundle application
(tmpdir / 'hgbroken-bundle').write("Obviously garbage")
(tmpdir / 'gitbroken-bundle').write("Garbage, yes, but Git garbage!")
with pytest.raises(grpc.RpcError) as exc_info_hg:
rpc_create_repository_from_bundle('hg', 'broken-bundle')
with pytest.raises(grpc.RpcError) as exc_info_git:
rpc_create_repository_from_bundle('git', 'broken-bundle')
assert exc_info_hg.value.code() == exc_info_git.value.code()
for vcs in ('hg', 'git'):
assert not target_repo_path(vcs, 'broken-bundle').exists()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment