Fix patching failing when decompressor produces no output

This commit is contained in:
Kovid Goyal 2021-10-03 12:57:32 +05:30
parent df1ecad7e9
commit 37f3328147
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -367,7 +367,7 @@ class DestFile:
self.close() self.close()
self.apply_metadata(is_symlink=True) self.apply_metadata(is_symlink=True)
elif self.ftype is FileType.regular: elif self.ftype is FileType.regular:
data = self.decompressor(data, is_last=is_last) decompressed = self.decompressor(data, is_last=is_last)
if self.actual_file is None: if self.actual_file is None:
self.make_parent_dirs() self.make_parent_dirs()
if self.ttype is TransmissionType.rsync: if self.ttype is TransmissionType.rsync:
@ -377,7 +377,8 @@ class DestFile:
flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC | getattr(os, 'O_CLOEXEC', 0) | getattr(os, 'O_BINARY', 0) flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC | getattr(os, 'O_CLOEXEC', 0) | getattr(os, 'O_BINARY', 0)
self.actual_file = open(os.open(self.name, flags, self.permissions), mode='r+b', closefd=True) self.actual_file = open(os.open(self.name, flags, self.permissions), mode='r+b', closefd=True)
af = cast(Union[IO[bytes], PatchFile], self.actual_file) af = cast(Union[IO[bytes], PatchFile], self.actual_file)
af.write(data) if decompressed or is_last:
af.write(decompressed)
self.bytes_written = af.tell() self.bytes_written = af.tell()
if is_last: if is_last:
self.close() self.close()