fix typo, use ancestors iterator
This commit is contained in:
parent
186ca8086d
commit
ee4d999770
1 changed files with 9 additions and 10 deletions
19
src/main.rs
19
src/main.rs
|
@ -13,19 +13,23 @@ fn main() {
|
|||
let cli = Cli::parse();
|
||||
|
||||
|
||||
let mut directory = path::absolute(cli.search_root.clone()).expect("Encountered error while parsing search root");
|
||||
let directory;
|
||||
|
||||
// resolution of the . path is always canonical, which is an issue here. This tests whether pwd ebv var contains a valid path, and if so prefers that.
|
||||
// resolution of the . path is always canonical, which is an issue here. This tests whether pwd env var contains a valid path, and if so prefers that.
|
||||
let pwd = env::var("PWD");
|
||||
let canonical_dir = fs::canonicalize(cli.search_root.clone()).expect("Encountered error while parsing search root");
|
||||
let test_dir = pwd.as_deref().map(path::Path::new);
|
||||
if cli.search_root == path::Path::new(".") && test_dir.clone().map(fs::canonicalize).is_ok_and(|r| r.is_ok_and(|p| canonical_dir == p)) {
|
||||
directory = test_dir.map(PathBuf::from).unwrap();
|
||||
} else {
|
||||
directory = path::absolute(cli.search_root.clone()).expect("Encountered error while parsing search root");
|
||||
}
|
||||
|
||||
let mut found = false;
|
||||
loop {
|
||||
let files = match fs::read_dir(&directory) {
|
||||
|
||||
for p in directory.ancestors() {
|
||||
|
||||
let files = match fs::read_dir(&p) {
|
||||
Ok(file) => file,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
@ -45,7 +49,7 @@ fn main() {
|
|||
let path = if !cli.output_dir_only {
|
||||
file.as_ref().unwrap().path()
|
||||
} else {
|
||||
directory.clone()
|
||||
p.to_path_buf()
|
||||
};
|
||||
|
||||
let out = if cli.output_cannonical {
|
||||
|
@ -65,11 +69,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
match directory.parent() {
|
||||
Some(parent) => directory = parent.to_path_buf(),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
|
|
Loading…
Reference in a new issue