瀏覽代碼

fix: info-json-download — sudo rsync crée fichier root, os.unlink échouait → 500

Le fichier /tmp créé par sudo rsync appartient à root.
os.unlink() échouait (PermissionError) → except retournait 500
→ client recevait None → .info.json silencieusement ignoré.

Fix : finally + sudo rm -rf pour le nettoyage du tmp.
Ajout log warning côté pull quand info.json absent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cédric Hansen 3 小時之前
父節點
當前提交
2c5c40dfe1
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      sources/app.py

+ 7 - 5
sources/app.py

@@ -794,6 +794,7 @@ def api_archive_info_json_download(name):
     if not sudo_exists(info_path):
         return jsonify({"error": "info.json introuvable"}), 404
     tmp_path = f"/tmp/backupmanager_dl_{name}.info.json"
+    content = None
     try:
         result = subprocess.run(["sudo", "rsync", info_path, tmp_path],
                                 capture_output=True, text=True)
@@ -801,13 +802,12 @@ def api_archive_info_json_download(name):
             return jsonify({"error": result.stderr.strip()}), 500
         with open(tmp_path, "rb") as f:
             content = f.read()
-        os.unlink(tmp_path)
-        from flask import Response as _R
-        return _R(content, mimetype="application/json")
     except Exception as exc:
-        if os.path.exists(tmp_path):
-            os.unlink(tmp_path)
         return jsonify({"error": str(exc)}), 500
+    finally:
+        subprocess.run(["sudo", "rm", "-rf", tmp_path], capture_output=True)
+    from flask import Response as _R
+    return _R(content, mimetype="application/json")
 
 
 @app.route("/api/v1/archives/<name>/download")
@@ -1094,6 +1094,8 @@ def _do_pull_latest(inst_id, remote_job_id):
                                 os.path.join(backup_dir, archive_name + ".info.json")],
                                check=True)
                 os.unlink(tmp_info)
+            else:
+                app.logger.warning(f"Pull {archive_name}: .info.json absent ou inaccessible sur {inst.name}")
 
             app.logger.info(f"Pull {archive_name} ← {inst.name} OK")
         except Exception as exc: