🟡 [M20] append_lines 吞掉行计数 I/O 错误并从 0 继续编号 #45
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
append_lines中count_existing_lines(path).unwrap_or(0)会在行计数失败时静默把现有行数当作 0。影响
如果文件在打开后被删除、权限变化或读取失败,追加行编号会从 0 重新开始,调用方无法感知底层 I/O 错误。
位置
crates/bench/src/data_gen.rs:90建议
让
count_existing_lines(path)?向上传播错误,保持append_lines的std::io::Result<()>语义。修复方案
提交:
f6081b9改动内容
1.
append_lines— 先计数再打开 + 错误传播将计数移到文件打开之前,
unwrap_or(0)改为?向上传播错误,保持std::io::Result<()>语义。2.
count_existing_lines— 逐行传播读取错误验证
test_append_lines_increases_line_count