style: apply rustfmt across bench and core crates
CI / ci (ubuntu-latest) (push) Has been cancelled
CI / ci (windows-latest) (push) Has been cancelled
CI / ci (ubuntu-latest) (push) Has been cancelled
CI / ci (windows-latest) (push) Has been cancelled
Pure formatting pass - no semantic changes. Mostly long-line reflow,
import statement reordering (alphabetical), and trailing-newline fixes
that had been accumulating in the working tree.
Affected files:
* crates/bench/src/{data_gen,main,mmap_reader,pread_reader,report,runner}.rs
* crates/bench/src/suites/{concurrent,growth,jump,memory,render,rotation,startup}.rs
* crates/core/src/io/{file_reader,index_cache,read_cache}.rs
* crates/core/src/{types.rs, watcher/file_watcher.rs}
This commit is contained in:
@@ -33,8 +33,8 @@ impl FileReader {
|
||||
} else {
|
||||
// SAFETY: 使用只读 Mmap(非 MmapMut),文件以只读方式打开。
|
||||
// memmap2 内部持有文件描述符,确保 mmap 期间文件不会被关闭。
|
||||
let m = unsafe { memmap2::Mmap::map(&file) }
|
||||
.map_err(|e| CoreError::Mmap(e.to_string()))?;
|
||||
let m =
|
||||
unsafe { memmap2::Mmap::map(&file) }.map_err(|e| CoreError::Mmap(e.to_string()))?;
|
||||
|
||||
// Layer 3: mmap 后立即 stat 同一 fd,检测截断(TOCTOU 缓解,非安全证明)
|
||||
let current_size = file.metadata()?.len();
|
||||
@@ -507,7 +507,11 @@ mod tests {
|
||||
reader.reload().unwrap();
|
||||
assert_eq!(reader.line_count(), 1);
|
||||
assert_eq!(reader.get_line(0), Some("new"));
|
||||
assert_eq!(reader.get_line(1), None, "old line should not be accessible");
|
||||
assert_eq!(
|
||||
reader.get_line(1),
|
||||
None,
|
||||
"old line should not be accessible"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::io::{Read as _, Write as _};
|
||||
use std::path::Path;
|
||||
|
||||
use crate::io::cache_util::{cache_path, CACHE_VERSION};
|
||||
use crate::io::cache_util::{CACHE_VERSION, cache_path};
|
||||
use crate::io::line_index::LineIndex;
|
||||
|
||||
pub struct IndexCache;
|
||||
@@ -47,11 +47,7 @@ impl IndexCache {
|
||||
///
|
||||
/// The file hash is derived from `data` (the same byte slice used to build the index),
|
||||
/// avoiding TOCTOU issues from re-reading the file from disk.
|
||||
pub fn save_with_hash(
|
||||
file_path: &Path,
|
||||
index: &LineIndex,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<()> {
|
||||
pub fn save_with_hash(file_path: &Path, index: &LineIndex, data: &[u8]) -> std::io::Result<()> {
|
||||
let dest = cache_path(file_path).ok_or_else(|| {
|
||||
std::io::Error::new(std::io::ErrorKind::NotFound, "cannot determine cache path")
|
||||
})?;
|
||||
@@ -382,6 +378,10 @@ mod tests {
|
||||
}
|
||||
|
||||
let final_data = std::fs::read(&dest).expect("dest file should exist");
|
||||
assert_eq!(final_data.len(), 64 * 1024, "final file must be exactly one payload");
|
||||
assert_eq!(
|
||||
final_data.len(),
|
||||
64 * 1024,
|
||||
"final file must be exactly one payload"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,4 +492,4 @@ mod tests {
|
||||
let err = cache.get(&file, u64::MAX, 1).unwrap_err();
|
||||
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user