forked from DGNum/colmena
src/util.rs: No need to list
This commit is contained in:
parent
0e0a1e84f0
commit
58f2bf391f
1 changed files with 8 additions and 30 deletions
36
src/util.rs
36
src/util.rs
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
|
@ -87,36 +86,15 @@ pub async fn hive_from_args(args: &ArgMatches<'_>) -> NixResult<Hive> {
|
||||||
let mut file_path = None;
|
let mut file_path = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut listing = match fs::read_dir(&cur) {
|
let flake = cur.join("flake.nix");
|
||||||
Ok(listing) => listing,
|
if flake.is_file() {
|
||||||
Err(e) => {
|
file_path = Some(flake);
|
||||||
// This can very likely fail in shared environments
|
|
||||||
// where users aren't able to list /home. It's not
|
|
||||||
// unexpected.
|
|
||||||
//
|
|
||||||
// It may not be immediately obvious to the user that
|
|
||||||
// we are traversing upwards to find hive.nix.
|
|
||||||
log::warn!("Could not traverse up ({:?}) to find hive.nix: {}", cur, e);
|
|
||||||
break;
|
break;
|
||||||
},
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let found = listing.find_map(|rdirent| {
|
let legacy = cur.join("hive.nix");
|
||||||
match rdirent {
|
if legacy.is_file() {
|
||||||
Err(e) => Some(Err(e)),
|
file_path = Some(legacy);
|
||||||
Ok(f) => {
|
|
||||||
if f.file_name() == "flake.nix" || f.file_name() == "hive.nix" {
|
|
||||||
Some(Ok(f))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(rdirent) = found {
|
|
||||||
let dirent = rdirent?;
|
|
||||||
file_path = Some(dirent.path());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue