feat: --repair 校验发现问题提示重传 + 各等级进度修复
This commit is contained in:
1 parent
742cbabde6
commit
4defbf8b1e
3 files changed
+252
-47
No files matched your search
+72
-3
@@ -509,7 +509,7 @@ def test_size_check_all_ok(tmp_path):
|
||||
src.mkdir(); dst.mkdir()
|
||||
(src / "a.bin").write_bytes(b"x" * 1000)
|
||||
(dst / "a.bin").write_bytes(b"x" * 1000)
|
||||
assert transfer.size_check(str(src), str(dst)) == (0, 0)
|
||||
assert transfer.size_check(str(src), str(dst)) == ([], [])
|
||||
|
||||
def test_size_check_detect_diff_and_missing(tmp_path):
|
||||
src = tmp_path / "s"; dst = tmp_path / "d"
|
||||
@@ -518,9 +518,78 @@ def test_size_check_detect_diff_and_missing(tmp_path):
|
||||
(dst / "a.bin").write_bytes(b"x" * 999) # 大小不同
|
||||
(src / "b.bin").write_bytes(b"y" * 100)
|
||||
# b.bin 目标缺失
|
||||
diff, miss = transfer.size_check(str(src), str(dst))
|
||||
assert diff == 1 and miss == 1
|
||||
diffs, missing = transfer.size_check(str(src), str(dst))
|
||||
assert diffs == ["a.bin"] and missing == ["b.bin"]
|
||||
|
||||
def test_verify_level_order():
|
||||
"""等级从快到慢的顺序固定"""
|
||||
assert transfer.VERIFY_LEVELS == ["ultrafast", "fast", "normal", "slow", "full"]
|
||||
|
||||
# ---------- 各等级校验进度 ----------
|
||||
|
||||
def test_stat_check_detects_size_and_mtime(tmp_path):
|
||||
src = tmp_path / "s"; dst = tmp_path / "d"
|
||||
src.mkdir(); dst.mkdir()
|
||||
(src / "ok.txt").write_text("good")
|
||||
(dst / "ok.txt").write_text("good")
|
||||
(src / "diff.txt").write_text("longer content here")
|
||||
(dst / "diff.txt").write_text("short")
|
||||
(src / "gone.txt").write_text("x")
|
||||
# gone.txt 目标缺失
|
||||
diffs, missing = transfer.stat_check(str(src), str(dst))
|
||||
assert "diff.txt" in diffs # 大小不同
|
||||
assert "gone.txt" in missing # 缺失
|
||||
assert "ok.txt" not in diffs
|
||||
|
||||
def test_stat_check_mtime_diff(tmp_path):
|
||||
"""mtime 不同但大小相同 → 记为差异"""
|
||||
src = tmp_path / "s"; dst = tmp_path / "d"
|
||||
src.mkdir(); dst.mkdir()
|
||||
(src / "a.txt").write_text("same")
|
||||
(dst / "a.txt").write_text("same")
|
||||
import time as _t
|
||||
old = _t.time() - 500
|
||||
os.utime(str(dst / "a.txt"), (old, old))
|
||||
diffs, _missing = transfer.stat_check(str(src), str(dst))
|
||||
assert "a.txt" in diffs
|
||||
|
||||
def test_stat_check_progress_callback(tmp_path):
|
||||
src = tmp_path / "s"; dst = tmp_path / "d"
|
||||
src.mkdir(); dst.mkdir()
|
||||
for i in range(50):
|
||||
(src / f"f{i}.txt").write_text("x")
|
||||
(dst / f"f{i}.txt").write_text("x")
|
||||
events = []
|
||||
transfer.stat_check(str(src), str(dst),
|
||||
on_progress=lambda i, n: events.append((i, n)))
|
||||
assert len(events) > 0 # 有进度回调
|
||||
assert events[-1] == (50, 50) # 最终回调
|
||||
|
||||
def test_size_check_progress_callback(tmp_path):
|
||||
src = tmp_path / "s"; dst = tmp_path / "d"
|
||||
src.mkdir(); dst.mkdir()
|
||||
for i in range(30):
|
||||
(src / f"f{i}.txt").write_text("x")
|
||||
(dst / f"f{i}.txt").write_text("x")
|
||||
events = []
|
||||
transfer.size_check(str(src), str(dst),
|
||||
on_progress=lambda i, n: events.append((i, n)))
|
||||
assert events and events[-1][0] == events[-1][1]
|
||||
|
||||
# ---------- 校验后修复 (--repair) ----------
|
||||
|
||||
def test_parse_repair():
|
||||
assert transfer.parse_args(["s", "d"]).repair is False
|
||||
assert transfer.parse_args(["--repair", "s", "d"]).repair is True
|
||||
|
||||
def test_build_repair_cmd(tmp_path):
|
||||
list_file = str(tmp_path / "list.txt")
|
||||
with open(list_file, "w") as f:
|
||||
f.write("a.flac\nsub/b.lrc\n")
|
||||
cmd, used = transfer.build_repair_cmd("src/", "dst/", list_file, "30000")
|
||||
joined = " ".join(cmd)
|
||||
assert cmd[0] == "rsync"
|
||||
assert f"--files-from={list_file}" in joined
|
||||
assert "--mkpath" in joined
|
||||
assert "--bwlimit=30000" in joined
|
||||
assert "src/" in joined and "dst/" in joined
|
||||
Reference in new issue
Block a user