Skip to content

Commit 7880c22

Browse files
committed
Fix _ftp_retrlines_native chunk parser
1 parent ba73f59 commit 7880c22

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ftpsync/ftp_target.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ def _addline(status, line):
494494
elif res_type in ("cdir", "pdir"):
495495
pass
496496
else:
497+
write_error("Could not parse '{}'".format(line))
497498
raise NotImplementedError(
498499
"MLSD returned unsupported type: {!r}".format(res_type)
499500
)
@@ -719,6 +720,7 @@ def _ftp_retrlines_native(self, command, callback, encoding):
719720

720721
def _on_read_line(line):
721722
# Line is a byte string
723+
# print(" line ", line)
722724
status = 2 # fault
723725
line_decoded = None
724726
try:
@@ -731,7 +733,6 @@ def _on_read_line(line):
731733
status = 1 # used fallback encoding
732734
except UnicodeDecodeError:
733735
raise
734-
# pass # fault
735736

736737
if compat.PY2:
737738
# line is a native binary `str`.
@@ -748,17 +749,19 @@ def _on_read_line(line):
748749

749750
def _on_read_chunk(chunk):
750751
buffer = local_var["buffer"]
751-
# print("read_c()", chunk, buffer)
752752
# Normalize line endings
753753
chunk = chunk.replace(b"\r\n", LF)
754754
chunk = chunk.replace(b"\r", LF)
755+
chunk = buffer + chunk
755756
try:
757+
# print("Add chunk ", chunk, "to buffer", buffer)
756758
while True:
757759
item, chunk = chunk.split(LF, 1)
758760
_on_read_line(item) # + LF)
759761
except ValueError:
760-
buffer += chunk
761-
# print("Add chunk ", chunk, "to buffer", buffer)
762+
pass
763+
# print("Rest chunk", chunk)
764+
local_var["buffer"] = chunk
762765

763766
self.ftp.retrbinary(command, _on_read_chunk)
764767

0 commit comments

Comments
 (0)