working relative path with clone and init

This commit is contained in:
grimhilt
2023-06-06 19:42:54 +02:00
parent 08a61ee1aa
commit 762ab25619
4 changed files with 65 additions and 40 deletions

View File

@@ -1,8 +1,29 @@
use std::env;
use std::path::{PathBuf, Path};
use crate::global::global::DIR_PATH;
use std::fs::canonicalize;
pub fn nextsync_root() -> Option<PathBuf> {
let mut path = env::current_dir().unwrap();
let d = DIR_PATH.lock().unwrap();
let mut path = match d.clone() {
Some(dir) => {
let tmp = PathBuf::from(dir).to_owned();
if tmp.is_absolute() {
tmp
} else {
let current_dir = env::current_dir().ok()?;
let abs = current_dir.join(tmp);
let canonicalized_path = canonicalize(abs).ok()?;
canonicalized_path
}
},
None => env::current_dir().ok()?,
};
dbg!(path.clone());
let root = loop {
path.push(".nextsync");
if path.exists() {