fix(import): never overwrite an existing file when importing a folder
This commit is contained in:
@@ -889,3 +889,42 @@ def test_imported_request_with_files_in_place_is_still_refused(client):
|
||||
"request_id": req_id,
|
||||
}]}).json()["results"][0]
|
||||
assert not res["ok"] and "bereits importiert" in res["error"]
|
||||
|
||||
|
||||
def test_two_titles_rendering_to_the_same_name_do_not_overwrite(client):
|
||||
"""Two books whose templates produce the same folder and file names must not
|
||||
silently replace each other - that loses files and confuses ABS."""
|
||||
root = client.tmp_path / "library" / "dcc"
|
||||
lib_id = client.post("/api/libraries", json={
|
||||
"name": "DCC", "media_type": "audiobook", "root_path": str(root),
|
||||
"folder_template": "{Series}", "file_template": "{Title}",
|
||||
}).json()["id"]
|
||||
ids = [client.post("/api/requests", json={
|
||||
"library_id": lib_id, "title": "Dungeon Crawler Carl",
|
||||
"series": "Dungeon Crawler Carl", "volume": v,
|
||||
}, params={"allow_duplicate": True}).json()["id"] for v in (1, 7)]
|
||||
|
||||
dests = []
|
||||
for n, req_id in enumerate(ids, 1):
|
||||
src = client.downloads / f"teil{n}"
|
||||
src.mkdir()
|
||||
for i in (1, 2):
|
||||
(src / f"{i:02d}.mp3").write_bytes(f"Teil {n} Datei {i}".encode())
|
||||
res = client.post("/api/import", json={"items": [{
|
||||
"path": str(src), "is_dir": True,
|
||||
"files": [str(f) for f in sorted(src.iterdir())], "request_id": req_id,
|
||||
}]}).json()["results"][0]
|
||||
dests.append(res)
|
||||
|
||||
assert dests[0]["ok"]
|
||||
assert not dests[1]["ok"]
|
||||
assert "already exists" in dests[1]["error"]
|
||||
# the first title is untouched and the second one still has its files
|
||||
folder = root / "Dungeon Crawler Carl"
|
||||
assert sorted(p.name for p in folder.iterdir()) == [
|
||||
"Dungeon Crawler Carl - Part 01.mp3", "Dungeon Crawler Carl - Part 02.mp3",
|
||||
]
|
||||
content = (folder / "Dungeon Crawler Carl - Part 01.mp3").read_bytes()
|
||||
assert b"Teil 1 Datei 1" in content and b"Teil 2" not in content
|
||||
assert sorted(p.name for p in (client.downloads / "teil2").iterdir()) == \
|
||||
["01.mp3", "02.mp3"]
|
||||
|
||||
Reference in New Issue
Block a user