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
This commit is contained in:
parent
803f0c4d9a
commit
7d371e2fbf
@ -116,18 +116,24 @@ def write_artworkdb(
|
|||||||
state["index"] += 1
|
state["index"] += 1
|
||||||
state["offset"] = 0
|
state["offset"] = 0
|
||||||
filename = _ithmb_filename(fmt_id, state["index"])
|
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:
|
def _write_payload(fmt_id: int, data: bytes) -> IthmbLocation:
|
||||||
state = ithmb_state[fmt_id]
|
state = ithmb_state[fmt_id]
|
||||||
if fmt_id not in ithmb_files:
|
if fmt_id not in ithmb_files:
|
||||||
_open_next(fmt_id)
|
_open_next(fmt_id)
|
||||||
elif state["offset"] > 0 and state["offset"] + len(data) > ITHMB_MAX_SIZE_BYTES:
|
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)
|
_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"])
|
filename = _ithmb_filename(fmt_id, state["index"])
|
||||||
offset = state["offset"]
|
|
||||||
ithmb_files[fmt_id].write(data)
|
|
||||||
state["offset"] += len(data)
|
|
||||||
return IthmbLocation(filename, offset)
|
return IthmbLocation(filename, offset)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user