Merge pull request #9491 from ThomasWaldmann/trailing-sparse-windows-1.4

fix spurious sparse test fail on win32, fixes #7616
This commit is contained in:
TW 2026-03-17 00:30:19 +01:00 committed by GitHub
commit 974340c58a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -834,6 +834,7 @@ Utilization of max. archive size: {csize_max:.0%}
with backup_io('open'):
fd = open(path, 'wb')
with fd:
trailing_hole = False
ids = [c.id for c in item.chunks]
for data in self.pipeline.fetch_many(ids, is_preloaded=True):
if pi:
@ -842,10 +843,18 @@ Utilization of max. archive size: {csize_max:.0%}
if sparse and zeros.startswith(data):
# all-zero chunk: create a hole in a sparse file
fd.seek(len(data), 1)
trailing_hole = True
else:
fd.write(data)
trailing_hole = False
with backup_io('truncate_and_attrs'):
pos = item_chunks_size = fd.tell()
if is_win32 and trailing_hole and pos > 0:
# Windows: truncate() does not zero-fill properly (no VDL update).
# Writing a single zero at the end forces NTFS to zero-fill the hole
# and update valid data length.
fd.seek(pos - 1)
fd.write(b"\0")
fd.truncate(pos)
fd.flush()
self.restore_attrs(path, item, fd=fd.fileno())