mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Don't clone unnecessarily
This commit is contained in:
parent
9e63b2c46c
commit
622887bcdc
|
@ -1,19 +1,21 @@
|
||||||
use std::{env, path::PathBuf};
|
use std::{
|
||||||
|
env,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FindRootDirectoryError;
|
pub struct FindRootDirectoryError;
|
||||||
|
|
||||||
pub fn find_agb_root_directory() -> Result<PathBuf, FindRootDirectoryError> {
|
pub fn find_agb_root_directory() -> Result<PathBuf, FindRootDirectoryError> {
|
||||||
let mut current_path = env::current_dir().map_err(|_| FindRootDirectoryError)?;
|
let current_path = env::current_dir().map_err(|_| FindRootDirectoryError)?;
|
||||||
|
|
||||||
while !current_path.clone().join("justfile").exists() {
|
let mut search_path: &Path = ¤t_path;
|
||||||
current_path = current_path
|
|
||||||
.parent()
|
while !search_path.join("justfile").exists() {
|
||||||
.ok_or(FindRootDirectoryError)?
|
search_path = search_path.parent().ok_or(FindRootDirectoryError)?;
|
||||||
.to_owned();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(current_path)
|
Ok(search_path.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -22,6 +24,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn find_agb_root_directory_works() {
|
fn find_agb_root_directory_works() {
|
||||||
find_agb_root_directory().unwrap();
|
let agb_root = find_agb_root_directory().unwrap();
|
||||||
|
assert!(agb_root.join("justfile").exists());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue