Преглед изворни кода

fix: remplacer find -printf par find+stat portable pour les listes SSH

find -printf est une extension GNU absente sur certains systèmes (BusyBox,
NAS…) — la commande échouait silencieusement et retournait une liste vide,
d'où l'absence d'archives dans la vue globale pour les destinations SSH.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cedric Hansen пре 2 недеља
родитељ
комит
0665205787
2 измењених фајлова са 17 додато и 5 уклоњено
  1. 11 3
      sources/blueprints/overview.py
  2. 6 2
      sources/retention.py

+ 11 - 3
sources/blueprints/overview.py

@@ -84,10 +84,18 @@ def _ssh_base(destination, data_dir):
 
 def _collect_ssh(destination, data_dir):
     remote_dir = shlex.quote(destination.remote_path)
+    # find -printf n'est pas disponible sur tous les systèmes (BusyBox, BSD…)
+    # On utilise cd + find + stat avec fallback BSD pour la portabilité
+    remote_cmd = (
+        f"cd {remote_dir} && find . -maxdepth 1 -name '*.tar' -type f 2>/dev/null"
+        " | sed 's|^\\./||'"
+        " | while IFS= read -r f; do"
+        " s=$(stat -c%s \"$f\" 2>/dev/null || stat -f%z \"$f\" 2>/dev/null || echo 0);"
+        " printf '%s\\t%s\\n' \"$f\" \"$s\";"
+        " done; true"
+    )
     result = subprocess.run(
-        _ssh_base(destination, data_dir) + [
-            f"find {remote_dir} -maxdepth 1 -name '*.tar' -printf '%f\\t%s\\n' 2>/dev/null || true"
-        ],
+        _ssh_base(destination, data_dir) + [remote_cmd],
         capture_output=True, text=True, timeout=20,
     )
     if result.returncode != 0:

+ 6 - 2
sources/retention.py

@@ -88,14 +88,18 @@ def apply_ssh_retention(job, destination, data_dir):
 
     remote_dir = shlex.quote(destination.remote_path)
     result = subprocess.run(
-        ssh_base + [f"find {remote_dir} -maxdepth 1 -name '*.tar' -printf '%f\\n' 2>/dev/null || true"],
+        ssh_base + [
+            f"cd {remote_dir} && find . -maxdepth 1 -name '*.tar' -type f 2>/dev/null"
+            " | sed 's|^\\./||'; true"
+        ],
         capture_output=True, text=True, timeout=30,
     )
     if result.returncode != 0:
         raise RuntimeError(f"Listage distant échoué : {result.stderr.strip()}")
 
     remote_archives = sorted(
-        [f for f in result.stdout.splitlines() if f.startswith(prefix) and f.endswith(".tar")],
+        [f.strip() for f in result.stdout.splitlines()
+         if f.strip().startswith(prefix) and f.strip().endswith(".tar")],
         key=_extract_date,
     )