MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / find_up

Method find_up

crates/opencode-util/src/filesystem.rs:60–84  ·  view source on GitHub ↗
(target: &str, start: P, stop: Option<P>)

Source from the content-addressed store, hash-verified

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(&current) {
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();

Callers

nothing calls this directly

Calls 1

newFunction · 0.85

Tested by

no test coverage detected