From 5d2ea643d40289e526c16b37e958d24cda18165e Mon Sep 17 00:00:00 2001 From: TheMightyTRexUK <196487809+TheMightyTRex@users.noreply.github.com> Date: Sun, 1 Nov 2026 21:05:11 +0000 Subject: [PATCH] Let download repair accept a library switched from hardlink to copy After an administrator changed a library's import method from hardlink to copy, held downloads could not be repaired: connection repair compared the whole frozen destination with the current one, so the changed mode failed with "The library destination changed; this repair cannot move an existing import", although the library location had not moved. Repair now compares the destination without the mode and accepts the mode when it is unchanged or is now copy. Copying moves nothing for a download that has not been imported yet. Any other destination change, or a switch from copy to hardlink, still needs a new selection. Co-Authored-By: Claude Opus 5.5 --- services/app/domain/download_repairs.py | 12 +++++++++++- tests/integration/test_download_repairs.py | 14 +++++++++++++- tests/unit/test_download_repair_destination.py | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_download_repair_destination.py diff --git a/services/app/domain/download_repairs.py b/services/app/domain/download_repairs.py index 625f25c4..f2b432db 100644 --- a/services/app/domain/download_repairs.py +++ b/services/app/domain/download_repairs.py @@ -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": @@ -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" ) diff --git a/tests/integration/test_download_repairs.py b/tests/integration/test_download_repairs.py index 621dbe51..fcdcd21c 100644 --- a/tests/integration/test_download_repairs.py +++ b/tests/integration/test_download_repairs.py @@ -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 @@ -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 ): diff --git a/tests/unit/test_download_repair_destination.py b/tests/unit/test_download_repair_destination.py new file mode 100644 index 00000000..99c0d464 --- /dev/null +++ b/tests/unit/test_download_repair_destination.py @@ -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"}})