Check if repo is already cloned

This commit is contained in:
southerntofu 2020-04-30 23:28:25 +02:00
parent ec55a274c3
commit ed17533c02
1 changed files with 25 additions and 8 deletions

View File

@ -14,26 +14,35 @@ pub struct Entry {
#[derive(Debug)]
pub struct Task {
name: OsString,
bin: PathBuf,
source: Option<String>,
dvcs: Option<String>,
config: HashMap<String, String>,
branch: Option<String>,
host: Option<String>
pub name: OsString,
pub bin: PathBuf,
pub source: Option<String>,
pub dvcs: Option<String>,
pub config: HashMap<String, String>,
pub branch: Option<String>,
pub host: Option<String>,
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<String> {
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)