diff --git a/swh/loader/svn/loader.py b/swh/loader/svn/loader.py --- a/swh/loader/svn/loader.py +++ b/swh/loader/svn/loader.py @@ -373,24 +373,11 @@ # before the post_load operation self.svnrepo.clean_fs(self.svnrepo.local_url) - def prepare(self): - if self.incremental: - latest_snapshot_revision = self._latest_snapshot_revision(self.origin.url) - if latest_snapshot_revision: - self.latest_snapshot, self.latest_revision = latest_snapshot_revision - self._snapshot = self.latest_snapshot - self._last_revision = self.latest_revision - - local_dirname = self._create_tmp_dir(self.temp_directory) - + def svn_repo(self, *args, **kwargs): + """Wraps the creation of SvnRepo object and handles not found repository + errors.""" try: - self.svnrepo = SvnRepo( - self.svn_url, - self.origin.url, - local_dirname, - self.max_content_size, - self.from_dump, - ) + return SvnRepo(*args, **kwargs) except SubversionException as e: error_msgs = [ "Unable to connect to a repository at URL", @@ -402,6 +389,24 @@ raise NotFound(e) raise + def prepare(self): + if self.incremental: + latest_snapshot_revision = self._latest_snapshot_revision(self.origin.url) + if latest_snapshot_revision: + self.latest_snapshot, self.latest_revision = latest_snapshot_revision + self._snapshot = self.latest_snapshot + self._last_revision = self.latest_revision + + local_dirname = self._create_tmp_dir(self.temp_directory) + + self.svnrepo = self.svn_repo( + self.svn_url, + self.origin.url, + local_dirname, + self.max_content_size, + self.from_dump, + ) + try: revision_start, revision_end = self.start_from() self.swh_revision_gen = self.process_svn_revisions( @@ -776,7 +781,7 @@ last_loaded_snp_and_rev = self._latest_snapshot_revision(self.origin.url) if last_loaded_snp_and_rev is not None: last_loaded_snp, last_loaded_rev = last_loaded_snp_and_rev - self.svnrepo = SvnRepo( + self.svnrepo = self.svn_repo( self.origin.url, self.origin.url, self.temp_dir, self.max_content_size ) stale_repository = self.svnrepo.head_revision() == last_loaded_svn_rev diff --git a/swh/loader/svn/tests/conftest.py b/swh/loader/svn/tests/conftest.py --- a/swh/loader/svn/tests/conftest.py +++ b/swh/loader/svn/tests/conftest.py @@ -7,6 +7,8 @@ import pytest +from swh.loader.svn.loader import SvnRepo + from .utils import create_repo @@ -45,3 +47,11 @@ def repo_url(tmpdir_factory): # create a repository return create_repo(tmpdir_factory.mktemp("repos")) + + +@pytest.fixture(autouse=True) +def svn_retry_sleep_mocker(mocker): + mocker.patch.object(SvnRepo.export.retry, "sleep") + mocker.patch.object(SvnRepo.checkout.retry, "sleep") + mocker.patch.object(SvnRepo.propget.retry, "sleep") + mocker.patch.object(SvnRepo.remote_access.retry, "sleep") diff --git a/swh/loader/svn/tests/test_externals.py b/swh/loader/svn/tests/test_externals.py --- a/swh/loader/svn/tests/test_externals.py +++ b/swh/loader/svn/tests/test_externals.py @@ -5,21 +5,13 @@ import pytest -from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump, SvnRepo +from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump from swh.loader.svn.utils import svn_urljoin from swh.loader.tests import assert_last_visit_matches, check_snapshot from .utils import CommitChange, CommitChangeType, add_commit, create_repo -@pytest.fixture(autouse=True) -def svn_retry_sleep_mocker(mocker): - mocker.patch.object(SvnRepo.export.retry, "sleep") - mocker.patch.object(SvnRepo.checkout.retry, "sleep") - mocker.patch.object(SvnRepo.propget.retry, "sleep") - mocker.patch.object(SvnRepo.remote_access.retry, "sleep") - - @pytest.fixture def external_repo_url(tmpdir_factory): # create a repository diff --git a/swh/loader/svn/tests/test_loader.py b/swh/loader/svn/tests/test_loader.py --- a/swh/loader/svn/tests/test_loader.py +++ b/swh/loader/svn/tests/test_loader.py @@ -2029,3 +2029,39 @@ loader = svn_loader_cls(**loader_params) assert loader.load() == {"status": "uneventful"} + + +@pytest.mark.parametrize("svn_loader_cls", [SvnLoader, SvnLoaderFromRemoteDump]) +def test_loader_svn_not_found_after_successful_visit( + swh_storage, datadir, tmp_path, svn_loader_cls +): + archive_name = "pkg-gourmet" + archive_path = os.path.join(datadir, f"{archive_name}.tgz") + repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) + + loader = svn_loader_cls(swh_storage, repo_url, temp_directory=tmp_path) + + assert loader.load() == {"status": "eventful"} + + assert_last_visit_matches( + loader.storage, + repo_url, + status="full", + type="svn", + snapshot=GOURMET_SNAPSHOT.id, + ) + check_snapshot(loader.snapshot, loader.storage) + + # simulate removal of remote repository + shutil.rmtree(repo_url.replace("file://", "")) + + loader = svn_loader_cls(swh_storage, repo_url, temp_directory=tmp_path) + + assert loader.load() == {"status": "uneventful"} + assert_last_visit_matches( + loader.storage, + repo_url, + status="not_found", + type="svn", + snapshot=None, + )