From 6319408bc28d56a7fe064db2682b637d5a194de8 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 28 Nov 2024 23:45:57 +0100
Subject: [PATCH] Don't try to sync file missing on both sides.

---
 src/sync.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

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()
 
 
-- 
2.30.2