From 2e8c8fe8c8460a23587b921fa9505161efce3006 Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Sun, 2 Aug 2020 11:08:11 +0800 Subject: [PATCH] feat: add find_parents_exists_dir --- src/util_file.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util_file.rs b/src/util_file.rs index 1b6919b..13e24d2 100644 --- a/src/util_file.rs +++ b/src/util_file.rs @@ -77,6 +77,20 @@ impl Iterator for JoinFilesReader { } } +pub fn find_parents_exists_dir(dir: &str) -> Option { + 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 { for f in files { match PathBuf::from(&resolve_file_path(f)) {