More work on rsync based receive

This commit is contained in:
Kovid Goyal 2021-11-16 14:21:42 +05:30
parent 0eac514e52
commit 1603b4b522
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 6 deletions

View File

@ -62,8 +62,8 @@ class File:
self.parent = ftc.parent
self.expanded_local_path = ''
self.file_id = str(next(file_counter))
self.compression_capable = self.ftype is FileType.regular and self.expected_size > 4096 and should_be_compressed(self.expanded_local_path)
self.decompressor: Union[ZlibDecompressor, IdentityDecompressor] = ZlibDecompressor() if self.compression_capable else IdentityDecompressor()
compression_capable = self.ftype is FileType.regular and self.expected_size > 4096 and should_be_compressed(self.remote_path)
self.decompressor: Union[ZlibDecompressor, IdentityDecompressor] = ZlibDecompressor() if compression_capable else IdentityDecompressor()
self.remote_symlink_value = b''
self.actual_file: Union[None, PatchFile, IO[bytes]] = None
@ -82,7 +82,8 @@ class File:
os.makedirs(parent, exist_ok=True)
self.actual_file = PatchFile(self.expanded_local_path) if self.expect_diff else open(self.expanded_local_path, 'wb')
base = self.actual_file.tell()
self.actual_file.write(data)
if data:
self.actual_file.write(data)
ans = self.actual_file.tell() - base
if is_last:
self.actual_file.close()
@ -293,7 +294,7 @@ class Manager:
read_signature = sr.st_size > 4096
yield FileTransmissionCommand(
action=Action.file, name=f.remote_path, file_id=f.file_id, ttype=TransmissionType.rsync if read_signature else TransmissionType.simple,
compression=Compression.zlib if f.compression_capable else Compression.none
compression=Compression.zlib if isinstance(f.decompressor, ZlibDecompressor) else Compression.none
).serialize()
if read_signature:
f.expect_diff = True
@ -354,7 +355,7 @@ class Manager:
is_last = ftc.action is Action.end_data
try:
amt_written = f.write_data(ftc.data, is_last)
except OSError as err:
except Exception as err:
return str(err)
self.progress_tracker.file_written(f, amt_written, is_last)
if is_last:

View File

@ -666,7 +666,7 @@ class ActiveSend:
if af.transmitted:
self.active_file = None
self.pending_chunks.extend(split_for_transfer(chunk, file_id=af.file_id, mark_last=af.transmitted))
return self.pending_chunks.popleft()
return self.pending_chunks.popleft() if self.pending_chunks else None
def return_chunk(self, ftc: FileTransmissionCommand) -> None:
self.pending_chunks.insert(0, ftc)