From: Christian Heller Date: Thu, 28 Nov 2024 22:45:57 +0000 (+0100) Subject: Don't try to sync file missing on both sides. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/edit?a=commitdiff_plain;h=6319408bc28d56a7fe064db2682b637d5a194de8;p=ytplom Don't try to sync file missing on both sides. --- diff --git a/src/sync.py b/src/sync.py index d0591f7..3d6a712 100755 --- a/src/sync.py +++ b/src/sync.py @@ -89,15 +89,20 @@ def main(): remote_db.commit_close() scp.put(PATH_DB_REMOTE, PATH_DB) os_remove(PATH_DB_REMOTE) - for host, port, direction, mover in ( - (config.remote, config.port_remote, 'local->remote', scp.put), - (config.host, config.port, 'remote->local', scp.get)): + missings = [] + for host, port in ((config.remote, config.port_remote), + (config.host, config.port)): url_missing = f'http://{host}:{port}/{PAGE_NAMES["missing"]}' with urlopen(url_missing) as response: - missing = json_loads(response.read()) - for path in (path_join(PATH_DOWNLOADS, path) for path in missing): + missings += [json_loads(response.read())] + for i, direction_mover in enumerate([('local->remote', scp.put), + ('remote->local', scp.get)]): + direction, mover = direction_mover + for path in (p for p in missings[i] + if p not in missings[int(not bool(i))]): + full_path = path_join(PATH_DOWNLOADS, path) print(f'SYNC: sending {direction} file {path}') - mover(path, path) + mover(full_path, full_path) scp.close()