From 7d371e2fbf1765a8be9a68bf31d0531801994149 Mon Sep 17 00:00:00 2001 From: Maksim Totmin Date: Sun, 31 May 2026 18:17:03 +0700 Subject: [PATCH] Fix ithmb append mode: preserve existing data across transfer sessions - Change ithmb file open from 'wb' (truncate) to 'ab' (append) - Compute write offset from actual file position via seek(0,2) - Prevents losing all previous artwork data on each transfer --- src/artwork/writer.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/artwork/writer.py b/src/artwork/writer.py index 9526f6e..28cd383 100644 --- a/src/artwork/writer.py +++ b/src/artwork/writer.py @@ -116,18 +116,24 @@ def write_artworkdb( state["index"] += 1 state["offset"] = 0 filename = _ithmb_filename(fmt_id, state["index"]) - ithmb_files[fmt_id] = open(os.path.join(artwork_dir, filename), "wb") + ithmb_files[fmt_id] = open(os.path.join(artwork_dir, filename), "ab") def _write_payload(fmt_id: int, data: bytes) -> IthmbLocation: state = ithmb_state[fmt_id] if fmt_id not in ithmb_files: _open_next(fmt_id) - elif state["offset"] > 0 and state["offset"] + len(data) > ITHMB_MAX_SIZE_BYTES: - _open_next(fmt_id) + else: + f = ithmb_files[fmt_id] + f.seek(0, 2) + cur_size = f.tell() + if cur_size > 0 and cur_size + len(data) > ITHMB_MAX_SIZE_BYTES: + _open_next(fmt_id) + f = ithmb_files[fmt_id] + f.seek(0, 2) + offset = f.tell() + f.write(data) + state["offset"] = offset + len(data) filename = _ithmb_filename(fmt_id, state["index"]) - offset = state["offset"] - ithmb_files[fmt_id].write(data) - state["offset"] += len(data) return IthmbLocation(filename, offset) try: