mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-10 17:32:13 -04:00
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:
commit
974340c58a
1 changed files with 9 additions and 0 deletions
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in a new issue