| 58 | } |
| 59 | |
| 60 | pub async fn find_up<P: AsRef<Path>>(target: &str, start: P, stop: Option<P>) -> Vec<PathBuf> { |
| 61 | let mut current = start.as_ref().to_path_buf(); |
| 62 | let stop = stop.map(|s| s.as_ref().to_path_buf()); |
| 63 | let mut result = Vec::new(); |
| 64 | |
| 65 | loop { |
| 66 | let search = current.join(target); |
| 67 | if Self::exists(&search).await { |
| 68 | result.push(search); |
| 69 | } |
| 70 | if stop.as_ref() == Some(¤t) { |
| 71 | break; |
| 72 | } |
| 73 | let parent = current.parent().map(|p| p.to_path_buf()); |
| 74 | if let Some(parent) = parent { |
| 75 | if parent == current { |
| 76 | break; |
| 77 | } |
| 78 | current = parent; |
| 79 | } else { |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | result |
| 84 | } |
| 85 | |
| 86 | pub async fn glob_up<P: AsRef<Path>>(pattern: &str, start: P, stop: Option<P>) -> Vec<PathBuf> { |
| 87 | let mut current = start.as_ref().to_path_buf(); |