This will panic on Windows:
fn main() {
let path = PathBuf::from("test.log");
write_some(&path);
write_some(&path);
write_some(&path);
let path2 = PathBuf::from("Test.log");
write_some(&path2);
write_some(&path2);
write_some(&path2);
}
fn write_some(path: &PathBuf) {
let mut writer = file_rotate::FileRotate::new(
path,
file_rotate::suffix::AppendCount::new(1),
file_rotate::ContentLimit::Lines(10),
file_rotate::compression::Compression::None,
None,
);
let _ = writeln!(writer, "Line 1: Hello World!");
for idx in 2..=7 {
let _ = writeln!(writer, "Line {}", idx);
}
}
thread 'main' panicked at C:\Users\Caelan.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\file-rotate-0.8.0\src\lib.rs:554:9:
assertion failed: !new_path.exists()
I think this is because scan_suffixes populates a BTreeSet of suffixes, and then when move_file_with_suffix executes it thinks there is no file to move because self.suffixes.get(&new_suffix_info).cloned() returns None, but Path.exists() returns true because windows is case insensitive.
On a more general note, I think logging should generally fail-safe, if something goes wrong, it should be best effort (not panic). After reviewing the code when looking into this issue, the number of .expect() and assert!()'s is.... troubling.
This will panic on Windows:
I think this is because
scan_suffixespopulates a BTreeSet of suffixes, and then when move_file_with_suffix executes it thinks there is no file to move becauseself.suffixes.get(&new_suffix_info).cloned()returns None, butPath.exists()returns true because windows is case insensitive.On a more general note, I think logging should generally fail-safe, if something goes wrong, it should be best effort (not panic). After reviewing the code when looking into this issue, the number of
.expect()andassert!()'s is.... troubling.