Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion services/app/domain/download_repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def destination_shape(value):
}


def same_destination(previous, current):
# Switching an unimported download from hardlink to copy moves nothing, and copy works
# where hardlinks cannot. Any other change still needs a new selection.
before, after = destination_shape(previous), destination_shape(current)
mode_ok = before.get("mode") == after.get("mode") or after.get("mode") == "copy"
before.pop("mode", None)
after.pop("mode", None)
return mode_ok and before == after


async def proposal(db, user, attempt, selection):
await member(db, user.id)
if user.role != "admin":
Expand Down Expand Up @@ -116,7 +126,7 @@ async def proposal(db, user, attempt, selection):
"restore the submitted route before connection repair",
)
configuration = await destination_configuration(db, destination)
if destination_shape(configuration) != destination_shape(frozen["destination"]):
if not same_destination(frozen["destination"], configuration):
raise HTTPException(
409, "The library destination changed; this repair cannot move an existing import"
)
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/test_download_repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ async def change(database, selected, kind="downloader"):
**destination.probe,
"configuration_revision": fingerprint(configuration),
} # Contract fixture; actual probes have their own filesystem/ABS suite.
elif kind == "copy":
# Hardlinks fail on some filesystems, so the library switches to copying files.
destination = await db.get(ImportDestination, selection.destination_id)
assert destination.mode == "hardlink"
destination.mode = "copy"
await db.flush()
configuration = await destination_configuration(db, destination)
destination.probe = {
**destination.probe,
"copy": True,
"configuration_revision": fingerprint(configuration),
}
else:
(await db.get(Integration, selection.downloader_id)).credential_generation += 1

Expand All @@ -82,7 +94,7 @@ async def state(database, identifier):
return attempt, row


@pytest.mark.parametrize("kind", ["downloader", "source", "backend"])
@pytest.mark.parametrize("kind", ["downloader", "source", "backend", "copy"])
async def test_reviewed_generations_resume_same_transfer_and_preserve_frozen_selection(
client, database, selected, submitted, downloader, kind
):
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_download_repair_destination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from app.domain.download_repairs import same_destination

BEFORE = {"root_key": "audio", "mode": "hardlink", "backend": {"generation": 1, "url": "abs"}}


def test_switching_to_copy_keeps_the_destination():
assert same_destination(BEFORE, {**BEFORE, "mode": "copy"})
assert same_destination(BEFORE, {**BEFORE, "backend": {"generation": 2, "url": "abs"}})


def test_other_changes_still_need_a_new_selection():
assert not same_destination({**BEFORE, "mode": "copy"}, BEFORE)
assert not same_destination(BEFORE, {**BEFORE, "mode": "copy", "root_key": "other"})
assert not same_destination(BEFORE, {**BEFORE, "backend": {"generation": 1, "url": "other"}})