Handle missing remote dirs in RemoteStorage.find

This commit is contained in:
Adriane Boyd 2022-11-21 09:00:56 +01:00
parent 89895a0bd5
commit 8bed15b116
2 changed files with 18 additions and 7 deletions

View File

@ -119,13 +119,15 @@ class RemoteStorage:
recent matching file is preferred.
"""
name = self.encode_name(str(path))
urls = []
if command_hash is not None and content_hash is not None:
url = self.make_url(path, command_hash, content_hash)
url = self.url / name / command_hash / content_hash
urls = [url] if url.exists() else []
elif command_hash is not None:
if (self.url / name / command_hash).exists():
urls = list((self.url / name / command_hash).iterdir())
else:
urls = []
if (self.url / name).exists():
for sub_dir in (self.url / name).iterdir():
urls.extend(sub_dir.iterdir())
if content_hash is not None:

View File

@ -906,6 +906,15 @@ def test_local_remote_storage():
assert file_.read() == content
def test_local_remote_storage_pull_missing():
# pulling from a non-existent remote pulls nothing gracefully
with make_tempdir() as d:
filename = "a.txt"
remote = RemoteStorage(d / "root", str(d / "remote"))
assert remote.pull(filename, command_hash="aaaa") is None
assert remote.pull(filename) is None
@pytest.mark.parametrize(
"reqs,output",
[