Skip to content

Commit

Permalink
Fixing sometimes choosing incorrect mount point if substring of each …
Browse files Browse the repository at this point in the history
…other
  • Loading branch information
DarkKronicle committed Jan 14, 2024
1 parent 03aa7ac commit 1e9df03
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,20 @@ fn home_topdir(mnt_points: &[MountPoint]) -> Result<PathBuf, Error> {

fn get_topdir_for_path<'a>(path: &Path, mnt_points: &'a [MountPoint]) -> &'a Path {
let root: &'static Path = Path::new("/");
let mut topdir = None;
let mut topdir: Option<&PathBuf> = None;
let mut path_length = 0;
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;
// If there is a /run mount and a /run/media/user mount, we want to prioritize the
// longest
let mount_length = &mount_point.mnt_dir.to_str().unwrap().len();
if topdir == None || mount_length > &path_length {

Check failure on line 632 in src/freedesktop.rs

View workflow job for this annotation

GitHub Actions / build (netbsd)

binary comparison to literal `Option::None`
path_length = *mount_length;
topdir = Some(&mount_point.mnt_dir);
}
}
}
if let Some(t) = topdir {
Expand Down

0 comments on commit 1e9df03

Please sign in to comment.