fix(ci): clear remaining macOS/Windows clippy lints and stabilize temp_db drop race on Linux arm64

This commit is contained in:
Tobi Lutke
2026-11-27 18:16:32 -05:00
parent e2bf29f01d
commit 5a25568d57
5 changed files with 63 additions and 50 deletions
+6 -5
View File
@@ -1,7 +1,8 @@
//! Measuring an NTFS volume from its master file table, the way `WizTree`
//! does: one read of every file record instead of a listing per directory.
//! On a disk of four million files the walk opens six hundred thousand
//! directories; this reads five gigabytes in a few large requests.
//! Measuring an NTFS volume from its master file table.
//!
//! Reads every file record in bulk instead of listing every directory: on a
//! disk of four million files the walk opens six hundred thousand directories,
//! whereas this reads five gigabytes in a few large requests.
//!
//! Only for a whole drive, `C:\`. The table costs the same to read whatever
//! part of it is wanted, so for a small directory the walk is faster.
@@ -1131,8 +1132,8 @@ impl Table<'_> {
}
self.child(entry, depth, descend).transpose()
};
let entries = self.entries(number);
const PARALLEL_LEVELS: usize = 3;
let entries = self.entries(number);
let children = if depth < PARALLEL_LEVELS {
entries
.par_iter()
+4 -5
View File
@@ -68,16 +68,14 @@ pub fn default_cache_db_path() -> Option<PathBuf> {
#[cfg(target_os = "macos")]
{
let home = std::env::var_os("HOME")?;
return Some(
Some(
PathBuf::from(home).join("Library/Caches/disktree/scan-cache.redb"),
);
)
}
#[cfg(windows)]
{
let base = std::env::var_os("LOCALAPPDATA")?;
return Some(
PathBuf::from(base).join("disktree/cache/scan-cache.redb"),
);
Some(PathBuf::from(base).join("disktree/cache/scan-cache.redb"))
}
#[cfg(not(any(target_os = "macos", windows)))]
{
@@ -259,6 +257,7 @@ pub struct MountView {
}
impl MountView {
#[cfg(any(target_os = "linux", test))]
fn parse(line: &str) -> Option<Self> {
let (left, right) = line.split_once(" - ")?;
let mut left = left.split_whitespace().skip(3);
+30 -23
View File
@@ -354,19 +354,23 @@ pub fn walk_parallel(
} else {
None
};
let mut mount_parents: FxHashSet<PathBuf> = FxHashSet::default();
for path in &never {
if let Some(parent) = path.parent() {
mount_parents.insert(parent.to_path_buf());
}
}
if let Some(mounts) = &foreign_mounts {
for path in mounts {
#[cfg(target_os = "linux")]
let mount_parents = {
let mut parents: FxHashSet<PathBuf> = FxHashSet::default();
for path in &never {
if let Some(parent) = path.parent() {
mount_parents.insert(parent.to_path_buf());
parents.insert(parent.to_path_buf());
}
}
}
if let Some(mounts) = &foreign_mounts {
for path in mounts {
if let Some(parent) = path.parent() {
parents.insert(parent.to_path_buf());
}
}
}
parents
};
let mut visited_dirs = FxHashSet::default();
if let Some(id) = inode_of(&root_meta) {
@@ -379,10 +383,10 @@ pub fn walk_parallel(
);
#[cfg(windows)]
let volume = if !config.options.follow_links {
crate::windows::walk_volume(&canonical_root)
} else {
let volume = if config.options.follow_links {
None
} else {
crate::windows::walk_volume(&canonical_root)
};
let ctx = Arc::new(WalkContext {
@@ -392,6 +396,7 @@ pub fn walk_parallel(
root_dev,
foreign_mounts,
never_scanned: never,
#[cfg(target_os = "linux")]
mount_parents,
visited_dirs: Mutex::new(visited_dirs),
cancel: config.cancel,
@@ -419,21 +424,21 @@ pub fn walk_parallel(
let run_walk = || -> io::Result<()> {
#[cfg(windows)]
if ctx.skip_oracle.is_none() {
if let Some(result) = crate::mft::scan(
if ctx.skip_oracle.is_none()
&& let Some(result) = crate::mft::scan(
root,
&canonical_root,
&ctx.options,
&ctx.cancel,
&ctx.progress,
) {
let built = result?;
*ctx.finished_root
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner) =
Some(built);
return Ok(());
}
)
{
let built = result?;
*ctx.finished_root
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner) =
Some(built);
return Ok(());
}
let (mut phase, mut effects) = walk_machine::step(
walk_machine::State::Idle,
@@ -647,6 +652,7 @@ struct WalkContext {
never_scanned: FxHashSet<PathBuf>,
/// Parent directories of every path in `never_scanned` / `foreign_mounts`.
/// Directories absent from this set skip all per-entry mount hash checks.
#[cfg(target_os = "linux")]
mount_parents: FxHashSet<PathBuf>,
visited_dirs: Mutex<FxHashSet<(u64, u64)>>,
cancel: Arc<AtomicBool>,
@@ -746,6 +752,7 @@ impl LeafSlab {
self.meta.len()
}
#[cfg(target_os = "linux")]
#[allow(
clippy::too_many_arguments,
reason = "flat SoA push avoids intermediate struct copies"
+16 -16
View File
@@ -448,10 +448,10 @@ fn file_id(id: u128) -> Option<u64> {
u64::try_from(id).ok().filter(|&low| low != 0)
}
/// `(volume serial, file index)` of what `path` names, following links: how
/// a walk that follows links notices it has been somewhere before. `None`
/// where there is no usable index; zero and all ones mean exactly that
/// ([MS-FSCC] 2.1.9).
/// `(volume serial, file index)` of what `path` names, following links.
///
/// Used to detect symlink loops; returns `None` where there is no usable index
/// (zero and all ones per [MS-FSCC] 2.1.9).
///
/// [MS-FSCC]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/2d3333fe-fc98-4a6f-98a2-4bb805aff407
pub fn identity(path: &Path) -> Option<(u64, u64)> {
@@ -461,11 +461,11 @@ pub fn identity(path: &Path) -> Option<(u64, u64)> {
.then(|| (info.volume_serial_number(), index))
}
/// Serial number of the volume every directory under `canonical` is on,
/// for a walk that does not follow links. Only a local drive has one:
/// mounted folders there are reparse points the walk takes for links,
/// while a share's DFS links are not, and lead to other servers' volumes.
/// `None` for a share, or when the serial cannot be read.
/// Serial number of the volume every directory under `canonical` is on.
///
/// Only local drives have one (mounted folders are reparse points, whereas a
/// share's DFS links lead to other servers' volumes). Returns `None` for a
/// share or when the serial cannot be read.
pub fn walk_volume(canonical: &Path) -> Option<u64> {
let Some(Component::Prefix(prefix)) = canonical.components().next() else {
return None;
@@ -610,9 +610,10 @@ pub fn elevated() -> bool {
unsafe { windows_sys::Win32::UI::Shell::IsUserAnAdmin() != 0 }
}
/// Whether `root` is a whole drive an administrator would read from its
/// file table: a drive letter's root, formatted NTFS. Anything else, from
/// a folder or a mounted folder to another file system, is walked either way.
/// Whether `root` is a whole NTFS drive readable from its file table.
///
/// Anything else — a subdirectory, mounted folder, or non-NTFS volume — falls
/// back to the regular directory walk.
pub fn file_table_readable(root: &Path) -> bool {
let canonical = root.canonicalize().unwrap_or_else(|_| root.to_path_buf());
let Some(letter) = drive_letter(&canonical) else {
@@ -673,10 +674,9 @@ pub fn run_elevated(program: &Path, args: &[OsString]) -> io::Result<()> {
}
}
/// Write out what the file system holds only in memory for the volume
/// holding `path`, its file table included. Flushing a volume takes write
/// access, so an administrator. Only a volume mounted as a drive letter:
/// for one mounted in a folder, `\\.\X:` would name the drive around it.
/// Flush in-memory NTFS metadata (including the MFT) for `path`'s volume.
///
/// Requires administrator write access and a drive-letter mount.
pub fn flush_volume(path: &Path) -> io::Result<()> {
let root = volume_root(path).ok_or_else(|| {
io::Error::new(io::ErrorKind::NotFound, "no volume holds the path")
+7 -1
View File
@@ -305,8 +305,14 @@ fn temp_db_mode_works_and_cleans_up_on_drop() {
assert!(db_path.as_ref().is_some_and(|p| p.exists()));
}
// Temp DB file should be removed once Scanner is dropped.
// Temp DB file should be removed once Scanner and its background worker
// release the last Arc<CacheDb>.
if let Some(path) = db_path {
let deadline =
std::time::Instant::now() + std::time::Duration::from_secs(2);
while path.exists() && std::time::Instant::now() < deadline {
std::thread::sleep(std::time::Duration::from_millis(10));
}
assert!(!path.exists(), "temp db should be cleaned up on drop");
}
}