fix: decrypt_db SKIP 与失败分开计数, 不把无密钥误报为失败 (#72)

decrypt_db 在遍历 .db 时, 遇到没匹配 key 的 db (e.g. migrate/
unspportmsg.db 这种迁移残留 / 微信内部不加密的库) print "SKIP: xxx
(无密钥)" 后会 failed += 1, summary 里就把这类合理跳过的 db 报成
"失败"。用户每次跑完都得 grep 一下确认那 N 个失败到底是真问题还是
SKIP 噪音。

参照 pytest (passed/failed/skipped) / rsync 的标准做法, SKIP 单独
计数, 不进 failed:

- 加 skipped 计数器
- SKIP 分支走 skipped += 1 (其余 HMAC / SQLite 校验失败仍记 failed)
- summary 多显示一栏 "K 跳过(无密钥)"

只动这 3 处; main() 末尾本来就没基于 failed 设 exit code, 不影响
退出码语义。

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Belugary
2026-05-05 22:48:05 +08:00
committed by GitHub
parent acd44376ba
commit 9764385617

View File

@@ -140,13 +140,14 @@ def main():
success = 0 success = 0
failed = 0 failed = 0
skipped = 0
total_bytes = 0 total_bytes = 0
for rel, path, sz in db_files: for rel, path, sz in db_files:
key_info = get_key_info(keys, rel) key_info = get_key_info(keys, rel)
if not key_info: if not key_info:
print(f"SKIP: {rel} (无密钥)") print(f"SKIP: {rel} (无密钥)")
failed += 1 skipped += 1
continue continue
enc_key = bytes.fromhex(key_info["enc_key"]) enc_key = bytes.fromhex(key_info["enc_key"])
@@ -176,7 +177,7 @@ def main():
failed += 1 failed += 1
print(f"\n{'='*60}") print(f"\n{'='*60}")
print(f"结果: {success} 成功, {failed} 失败, 共 {len(db_files)}") print(f"结果: {success} 成功, {failed} 失败, {skipped} 跳过(无密钥),{len(db_files)}")
print(f"解密数据量: {total_bytes/1024/1024/1024:.1f}GB") print(f"解密数据量: {total_bytes/1024/1024/1024:.1f}GB")
print(f"解密文件在: {OUT_DIR}") print(f"解密文件在: {OUT_DIR}")