Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 15, 2024
1 parent 0b42fc0 commit 73ca3ec
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,7 @@ fn home_topdir(mnt_points: &[MountPoint]) -> Result<PathBuf, Error> {

fn get_first_topdir_containing_path<'a>(path: &Path, mnt_points: &'a [MountPoint]) -> &'a Path {
let root: &'static Path = Path::new("/");
let mut topdir: Option<&Path> = None;
for mount_point in mnt_points {
if mount_point.mnt_dir == root {
continue;
}
if path.starts_with(&mount_point.mnt_dir) {
topdir = Some(&mount_point.mnt_dir);
break;
}
}
topdir.unwrap_or(root)
mnt_points.iter().map(|mp| mp.mnt_dir.as_path()).find(|mount_path| path.starts_with(mount_path)).unwrap_or(root)
}

struct MountPoint {
Expand All @@ -640,10 +630,12 @@ struct MountPoint {
}

fn get_sorted_mount_points() -> Result<Vec<MountPoint>, Error> {
// Returns longest mount points first
let mut mount_points = get_mount_points()?;
mount_points
.sort_unstable_by(|a, b| b.mnt_dir.as_os_str().as_bytes().len().cmp(&a.mnt_dir.as_os_str().as_bytes().len()));
mount_points.sort_unstable_by(|a, b| {
let a = a.mnt_dir.as_os_str().as_bytes().len();
let b = b.mnt_dir.as_os_str().as_bytes().len();
a.cmp(&b).reverse()
});
Ok(mount_points)
}

Expand Down

0 comments on commit 73ca3ec

Please sign in to comment.