Psykopear / fuzzle

Fast application launcher
MIT License
14 stars 3 forks source link

Panics when a data directory has no applications subdirectory. #2

Closed synasius closed 4 years ago

synasius commented 4 years ago

When fuzzle builds its cache based on .desktop files, it assumes that each data directory listed by xdg has an applications subdirectory.

This is not always the case and when it's not fuzzle panics. This is the code responsible for the panic.

pub fn build_cache() -> Vec<SearchResult> {
    let mut results: Vec<SearchResult> = Vec::new();
    // Build SearchResults for all desktop files we can find
    for mut data_dir in search_dirs() {
        data_dir.push("applications");    // <--- here you push applications
        results.append(
            &mut fs::read_dir(data_dir)
                .expect("Can't find data dir")
                .filter_map(|path| searchresult_from_desktopentry(&path.unwrap().path()))
                .collect(),
        );
    }
    // ...
}

After you append applications to each data dir path I would check if the resulting directory exists before you try to read its entries.

Psykopear commented 4 years ago

Fixed