tui.py: 上传成功后自动清理临时产物 (失败保留可续传)
This commit is contained in:
+28
-1
@@ -7,6 +7,7 @@ vue-tui 的 raw mode 输入无法配合 IME, Python cooked-mode input() 可以)
|
||||
流程: 直接驱动 7z-encrypt 客户端模块 CLI, 实时透传进度输出。
|
||||
"""
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -36,6 +37,28 @@ def _clean(s: str) -> str:
|
||||
return s.strip().strip("'\"") if s else ""
|
||||
|
||||
|
||||
def cleanup_artifacts(path: str) -> None:
|
||||
"""上传成功后清理临时产物 (密文/分卷/init json/清单)
|
||||
|
||||
失败时不清: 断点续传依赖卷文件 + init json。
|
||||
"""
|
||||
removed = 0
|
||||
for pattern in (
|
||||
path + ".enc",
|
||||
path + ".enc.part*",
|
||||
path + ".init.json",
|
||||
path + "_manifest.json",
|
||||
):
|
||||
for p in glob.glob(pattern):
|
||||
try:
|
||||
os.remove(p)
|
||||
removed += 1
|
||||
except OSError:
|
||||
pass
|
||||
if removed:
|
||||
print(f"[清理] 已删除 {removed} 个临时文件")
|
||||
|
||||
|
||||
def upload() -> None:
|
||||
print("--- 上传文件 ---")
|
||||
path = _clean(input("文件路径: "))
|
||||
@@ -61,7 +84,11 @@ def upload() -> None:
|
||||
|
||||
print("\n[2/2] 上传 ...")
|
||||
code = run(["transfer.py", "--server", server, "--init", init_json, "--manifest", manifest])
|
||||
print("[完成]" if code == 0 else "[失败] 上传出错")
|
||||
if code == 0:
|
||||
print("[完成]")
|
||||
cleanup_artifacts(path) # 上传成功, 清理临时产物
|
||||
else:
|
||||
print("[失败] 上传出错 (临时文件保留, 可续传)")
|
||||
|
||||
|
||||
def tasks() -> None:
|
||||
|
||||
Reference in New Issue
Block a user