Skip to content

Commit

Permalink
linux: fix walking directory tree
Browse files Browse the repository at this point in the history
  • Loading branch information
liias committed Sep 24, 2024
1 parent 746eb5b commit a1417bf
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/linux/linux_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,23 @@ impl OsHelper {
}

fn freedesktop_find_all_desktop_entries(content_type: &str) -> Vec<DesktopEntryHolder> {
let all_search_paths = default_paths();

// remove duplicate entries (e.g XDG_DATA_DIRS sometimes has every path twice)
let set: HashSet<PathBuf> = all_search_paths.into_iter().collect();
let unique_search_paths = default_paths()
.into_iter()
// remove duplicate entries (e.g XDG_DATA_DIRS sometimes has every path twice)
.collect::<HashSet<PathBuf>>()
.into_iter();

// collect all .desktop file paths and map them by file name to remove duplicate files,
// even if they exist in different directories
let mut desktop_file_paths_by_filename: BTreeMap<_, PathBuf> = set
.into_iter()
.filter_map(|file_path| {
file_path
.file_name()
.map(|a| a.to_owned())
.map(|file_name| (file_name, file_path))
})
.collect();
let mut desktop_file_paths_by_filename: BTreeMap<_, PathBuf> =
Iter::new(unique_search_paths)
.filter_map(|file_path| {
file_path
.file_name()
.map(|a| a.to_owned())
.map(|file_name| (file_name, file_path))
})
.collect();

let cleaned_desktop_file_paths: Vec<PathBuf> =
desktop_file_paths_by_filename.into_values().collect();
Expand Down

0 comments on commit a1417bf

Please sign in to comment.