MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / find_max_id_in_dir

Function find_max_id_in_dir

crates/hyperqueue/src/common/serverdir.rs:107–125  ·  view source on GitHub ↗

Finds all child directories in the given directory. For each directory, tries to parse its name as an integer. Returns the maximum found successfully parsed integer or [`None`] if no integer was found.

(directory: &Path)

Source from the content-addressed store, hash-verified

105/// For each directory, tries to parse its name as an integer.
106/// Returns the maximum found successfully parsed integer or [`None`] if no integer was found.
107fn find_max_id_in_dir(directory: &Path) -> Option<u64> {
108 if let Ok(entries) = std::fs::read_dir(directory) {
109 entries
110 .filter_map(|entry| {
111 entry.ok().and_then(|entry| {
112 match entry.metadata().ok().map(|m| m.is_dir()).unwrap_or(false) {
113 true => entry
114 .file_name()
115 .to_str()
116 .and_then(|f| f.parse::<u64>().ok()),
117 false => None,
118 }
119 })
120 })
121 .max()
122 } else {
123 None
124 }
125}
126
127fn create_new_server_dir(directory: &Path) -> crate::Result<PathBuf> {
128 let max_id = find_max_id_in_dir(directory).unwrap_or(0);

Callers 1

create_new_server_dirFunction · 0.85

Calls 2

to_strMethod · 0.80
metadataMethod · 0.45

Tested by

no test coverage detected