From 91578fe8979ebe87d7302acd09bf66392327a250 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 3 Mar 2024 21:51:32 +0100 Subject: pkgs/profpatsch/nman: always enumerate all manpages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First step towards getting some info about which manpages are indeed available if we don’t find any. --- pkgs/profpatsch/nman/nman.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/pkgs/profpatsch/nman/nman.rs b/pkgs/profpatsch/nman/nman.rs index 4e3e71dc..36348ea3 100644 --- a/pkgs/profpatsch/nman/nman.rs +++ b/pkgs/profpatsch/nman/nman.rs @@ -408,23 +408,16 @@ impl Main { // expected sub directory of share/man or, if no section // is given, all potential sub directories - let mut section_dirs: Vec<(OsString, PathBuf)> = match section { - Some(s) => { - let dir_name = OsString::from(format!("man{}", s)); - let dir_path = path.join(dir_name.as_os_str()); - - if dir_path.exists() { - vec![(dir_name, dir_path)] - } else { - Vec::new() - } - } - None => read_dir(path.as_path()) - .map_err(NmanError::IO)? - .filter_map(|entry| entry.ok()) - .map(|e| (e.file_name(), e.path())) - .collect(), - }; + let mut section_dirs: Vec<(OsString, PathBuf)> = Self::enumerate_man_pages(&path)?; + + if let Some(sect) = section { + let dir_name = OsString::from(format!("man{}", sect)); + let dir_path = path.join(dir_name.as_os_str()); + section_dirs = section_dirs + .into_iter() + .find(|(_, dp)| dp == &dir_path) + .map_or(Vec::new(), |x| vec![x]); + } // sorting should be ascending in terms of numerics, // apart from that, not many requirements @@ -462,6 +455,15 @@ impl Main { Ok(OutputDirResult::NoManPageFound) } + fn enumerate_man_pages<'a>(path: &PathBuf) -> Result, NmanError<'a>> { + Ok(read_dir(path.as_path()) + .map_err(NmanError::IO)? + // ignore directories/files that cannot be read + .filter_map(|entry| entry.ok()) + .map(|e| (e.file_name(), e.path())) + .collect()) + } + /// Realises the given derivation output using `nix-store --realise` and /// returns the path to the output directory. fn build_drv_with_output<'a>( -- cgit 1.4.1