From 04bef223a381fc2f2f4db94766c085ca8acda9e3 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Thu, 1 Jun 2023 23:58:10 +0200 Subject: [PATCH] get nextsync_root --- src/utils.rs | 1 + src/utils/path.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/utils.rs create mode 100644 src/utils/path.rs diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..4da9789 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1 @@ +pub mod path; diff --git a/src/utils/path.rs b/src/utils/path.rs new file mode 100644 index 0000000..cd020cc --- /dev/null +++ b/src/utils/path.rs @@ -0,0 +1,19 @@ +use std::env; +use std::path::{PathBuf, Path}; + +pub fn nextsync_root() -> Option { + let mut path = env::current_dir().unwrap(); + let root = loop { + path.push(".nextsync"); + if path.exists() { + path.pop(); + break Some(path); + } + path.pop(); + path.pop(); + if path == Path::new("/") { + break None; + } + }; + root +}