From ed17533c02a2843aeb2d521da1eb36f910edff35 Mon Sep 17 00:00:00 2001 From: southerntofu Date: Thu, 30 Apr 2020 23:28:25 +0200 Subject: [PATCH] Check if repo is already cloned --- src/db.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/db.rs b/src/db.rs index a5b2545..81f3af9 100644 --- a/src/db.rs +++ b/src/db.rs @@ -14,26 +14,35 @@ pub struct Entry { #[derive(Debug)] pub struct Task { - name: OsString, - bin: PathBuf, - source: Option, - dvcs: Option, - config: HashMap, - branch: Option, - host: Option + pub name: OsString, + pub bin: PathBuf, + pub source: Option, + pub dvcs: Option, + pub config: HashMap, + pub branch: Option, + pub host: Option, + pub cloned: bool, } impl Task { pub fn new(base_dir: PathBuf, name: OsString) -> Task { let t = Entry::new(base_dir, name.clone()); + let source = t.source(); + let cloned = source.clone().map_or(false, |src| { + let mut path = t.base_dir.clone(); + path.push(format!(".{}", t.name.to_str().expect("WTF"))); + path.is_dir() + }); Task { name: name.clone(), bin: PathBuf::from(name.clone()), - source: t.source(), + source, dvcs: t.dvcs(), config: HashMap::new(), branch: t.branch(), host: t.host(), + cloned, + } } } @@ -68,6 +77,12 @@ impl Entry { pub fn host(&self) -> Option { self.read_setting("branch") } + + pub fn has_dir(&self, name: &str) -> bool { + let mut path = self.base_dir.clone(); + path.push(name); + return path.is_dir(); + } } pub struct Database { @@ -111,6 +126,8 @@ impl Database { Task::new(self.base_dir.clone(), path.file_name().expect("WTF").to_os_string()) ); } + + } /// Reads the file and strips whitespace (newline including)