home · contact · privacy
Don't try to sync file missing on both sides. master
authorChristian Heller <c.heller@plomlompom.de>
Thu, 28 Nov 2024 22:45:57 +0000 (23:45 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 28 Nov 2024 22:45:57 +0000 (23:45 +0100)
src/sync.py

index d0591f74cd80da518b0671402aed826369f716ed..3d6a71245db1eb93a50c149ecd5a16f2071134a8 100755 (executable)
@@ -89,15 +89,20 @@ def main():
     remote_db.commit_close()
     scp.put(PATH_DB_REMOTE, PATH_DB)
     os_remove(PATH_DB_REMOTE)
     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:
         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}')
             print(f'SYNC: sending {direction} file {path}')
-            mover(path, path)
+            mover(full_path, full_path)
     scp.close()
 
 
     scp.close()