Audit writer: open a record-less log, share the log-name rule, keep the lock file
M3a review findings 1, 2, 4 and part of 5. One empty log file made brokerd panic at startup (files[len - 2]); it now opens as an empty log. brokerd's name check tested one month digit, so a file bxctl ignored could become brokerd's latest file; both now use proto::is_audit_log_name. Writer no longer unlinks audit/.lock, which opened a two-writer window. No unwrap in short_check. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,7 @@ pub fn run(home: &Path, out: &mut dyn Write) -> std::io::Result<bool> {
|
||||
Ok(name) => name,
|
||||
Err(_) => continue,
|
||||
};
|
||||
if is_audit_log(&name) {
|
||||
if proto::is_audit_log_name(&name) {
|
||||
names.push(name);
|
||||
}
|
||||
}
|
||||
@@ -65,26 +65,3 @@ pub fn run(home: &Path, out: &mut dyn Write) -> std::io::Result<bool> {
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// True if `name` is a `YYYY-MM-DD.jsonl` audit log: ten characters, digits with `-` at positions
|
||||
/// 4 and 7, then `.jsonl`.
|
||||
fn is_audit_log(name: &str) -> bool {
|
||||
let date = match name.strip_suffix(".jsonl") {
|
||||
Some(date) => date,
|
||||
None => return false,
|
||||
};
|
||||
if date.len() != 10 {
|
||||
return false;
|
||||
}
|
||||
let bytes = date.as_bytes();
|
||||
for (i, &b) in bytes.iter().enumerate() {
|
||||
if i == 4 || i == 7 {
|
||||
if b != b'-' {
|
||||
return false;
|
||||
}
|
||||
} else if !b.is_ascii_digit() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user