1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 07:30:05 +08:00

feat: add find_parents_exists_dir

This commit is contained in:
2020-08-02 11:08:11 +08:00
parent 328f4c503f
commit 2e8c8fe8c8

View File

@@ -77,6 +77,20 @@ impl Iterator for JoinFilesReader {
}
}
pub fn find_parents_exists_dir(dir: &str) -> Option<PathBuf> {
match PathBuf::from(".").canonicalize() {
Err(_) => None,
Ok(mut path) => loop {
if path.join(dir).is_dir() {
return Some(path);
}
if !path.pop() {
return None;
}
}
}
}
pub fn locate_file(files: &[String]) -> Option<PathBuf> {
for f in files {
match PathBuf::from(&resolve_file_path(f)) {