sync errors

This commit is contained in:
2026-05-10 16:26:21 +02:00
parent 08b99ab340
commit 3f3af96224
+10 -1
View File
@@ -83,6 +83,7 @@ def list_new_zips(cfg: SFTPConfig) -> list[RemoteZip]:
transport = _make_transport(cfg) transport = _make_transport(cfg)
sftp = paramiko.SFTPClient.from_transport(transport) sftp = paramiko.SFTPClient.from_transport(transport)
try: try:
log.info("Walking remote directory tree from %s ...", cfg.remote_path)
all_zips = _walk_zips(sftp, cfg.remote_path) all_zips = _walk_zips(sftp, cfg.remote_path)
new_zips = [z for z in all_zips if not db.is_zip_processed(z.remote_path)] new_zips = [z for z in all_zips if not db.is_zip_processed(z.remote_path)]
log.info("Remote: %d zip(s) total, %d new", len(all_zips), len(new_zips)) log.info("Remote: %d zip(s) total, %d new", len(all_zips), len(new_zips))
@@ -109,16 +110,24 @@ def download(cfg: SFTPConfig, remote_zip: RemoteZip, dest_dir: str) -> Path:
def _walk_zips(sftp: paramiko.SFTPClient, remote_dir: str) -> list[RemoteZip]: def _walk_zips(sftp: paramiko.SFTPClient, remote_dir: str) -> list[RemoteZip]:
results: list[RemoteZip] = [] results: list[RemoteZip] = []
log.info("Listing %s ...", remote_dir)
try: try:
entries = sftp.listdir_attr(remote_dir) entries = sftp.listdir_attr(remote_dir)
except IOError as e: except IOError as e:
log.warning("Cannot list %s: %s", remote_dir, e) log.warning("Cannot list %s: %s", remote_dir, e)
return results return results
subdirs = []
zips_here = 0
for entry in entries: for entry in entries:
full_path = posixpath.join(remote_dir, entry.filename) full_path = posixpath.join(remote_dir, entry.filename)
if stat.S_ISDIR(entry.st_mode): if stat.S_ISDIR(entry.st_mode):
results.extend(_walk_zips(sftp, full_path)) subdirs.append(full_path)
elif entry.filename.lower().endswith(".zip"): elif entry.filename.lower().endswith(".zip"):
results.append(RemoteZip(remote_path=full_path, file_size=entry.st_size or 0)) results.append(RemoteZip(remote_path=full_path, file_size=entry.st_size or 0))
zips_here += 1
log.info(" %s: %d entries, %d zip(s), %d subdir(s)", remote_dir, len(entries), zips_here, len(subdirs))
for subdir in subdirs:
results.extend(_walk_zips(sftp, subdir))
return results return results