Skip to content

Commit

Permalink
refactor: extract a function
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Nov 25, 2024
1 parent 4446031 commit 3e51cb2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/app/sub/hdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ use sysinfo::DiskKind;
pub fn any_path_is_in_hdd<Disk>(
disks: &[Disk],
paths: &[PathBuf],
get_disk_kind: impl Fn(&Disk) -> DiskKind,
get_disk_kind: impl Fn(&Disk) -> DiskKind + Copy,
get_mount_point: impl Fn(&Disk) -> &Path + Copy,
) -> bool {
paths
.iter()
.filter_map(|file| fs::canonicalize(file).ok())
.any(|path| {
if let Some(mount_point) = find_mount_point(&path, disks.iter().map(get_mount_point)) {
disks.iter().any(|disk| {
get_disk_kind(disk) == DiskKind::HDD && get_mount_point(disk) == mount_point
})
} else {
false
}
.any(|path| path_is_in_hdd(&path, disks, get_disk_kind, get_mount_point))
}

pub fn path_is_in_hdd<Disk>(
path: &Path,
disks: &[Disk],
get_disk_kind: impl Fn(&Disk) -> DiskKind,
get_mount_point: impl Fn(&Disk) -> &Path + Copy,
) -> bool {
if let Some(mount_point) = find_mount_point(path, disks.iter().map(get_mount_point)) {
disks.iter().any(|disk| {
get_disk_kind(disk) == DiskKind::HDD && get_mount_point(disk) == mount_point
})
} else {
false
}
}

0 comments on commit 3e51cb2

Please sign in to comment.