mirror of https://github.com/borgbackup/borg.git
fixup: invert nesting of context managers
cleaner teardown of contexts: close mmap, close src_fd (reading), close dst_fd (and rename) maybe it was not a real problem to rename a still open-for-reading / mmapped file, but in any case it is cleaner like now.
This commit is contained in:
parent
b198160257
commit
bf8706b741
|
@ -1492,6 +1492,7 @@ class LoggedIO:
|
||||||
with SaveFile(filename, binary=True) as fd:
|
with SaveFile(filename, binary=True) as fd:
|
||||||
fd.write(MAGIC)
|
fd.write(MAGIC)
|
||||||
return
|
return
|
||||||
|
with SaveFile(filename, binary=True) as dst_fd:
|
||||||
with open(filename, 'rb') as src_fd:
|
with open(filename, 'rb') as src_fd:
|
||||||
# note: file must not be 0 size or mmap() will crash.
|
# note: file must not be 0 size or mmap() will crash.
|
||||||
with mmap.mmap(src_fd.fileno(), 0, access=mmap.ACCESS_READ) as mm:
|
with mmap.mmap(src_fd.fileno(), 0, access=mmap.ACCESS_READ) as mm:
|
||||||
|
@ -1499,7 +1500,6 @@ class LoggedIO:
|
||||||
data = memoryview(mm)
|
data = memoryview(mm)
|
||||||
d = data
|
d = data
|
||||||
try:
|
try:
|
||||||
with SaveFile(filename, binary=True) as dst_fd:
|
|
||||||
dst_fd.write(MAGIC)
|
dst_fd.write(MAGIC)
|
||||||
while len(d) >= self.header_fmt.size:
|
while len(d) >= self.header_fmt.size:
|
||||||
crc, size, tag = self.header_fmt.unpack(d[:self.header_fmt.size])
|
crc, size, tag = self.header_fmt.unpack(d[:self.header_fmt.size])
|
||||||
|
|
Loading…
Reference in New Issue