fix: clean up -shm/-wal residuals left by sqlite3 verification (#87)
The post-decrypt verification step (sqlite3.connect(out_path) + table list, around line 163) opens the freshly-written .db in default journal mode. Even though the connection is closed cleanly, SQLite leaves behind empty <db>-shm and <db>-wal companion files in OUT_DIR. Downstream tools that later open the same .db will see those companion files and try to roll the (empty / stale) WAL forward, producing "database disk image is malformed" or silently masking the most recent pages. The decrypted DB itself is fine — the residuals are pure noise from the verification connection. Fix: after the verification block (success or failure), unconditionally os.remove() out_path + "-shm" and out_path + "-wal" if present. Errors during cleanup are swallowed. Tests: existing tests/ pass (168/168). The cleanup is additive and only runs after the existing verification path; no behavior change for callers that do not inspect OUT_DIR for companion files. Scope: 10 lines in decrypt_db.py. No public API change, no schema change, no new dependency.
This commit is contained in:
@@ -176,6 +176,16 @@ def main():
|
||||
else:
|
||||
failed += 1
|
||||
|
||||
# 清理 sqlite3.connect() 验证遗留的 -shm/-wal 空文件
|
||||
# 避免后续工具打开 .db 时优先读旧 WAL 报 "database disk image is malformed"
|
||||
for suffix in ("-shm", "-wal"):
|
||||
residual = out_path + suffix
|
||||
if os.path.exists(residual):
|
||||
try:
|
||||
os.remove(residual)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"结果: {success} 成功, {failed} 失败, {skipped} 跳过(无密钥), 共 {len(db_files)} 个")
|
||||
print(f"解密数据量: {total_bytes/1024/1024/1024:.1f}GB")
|
||||
|
||||
Reference in New Issue
Block a user