diff --git a/src/main.rs b/src/main.rs index e486d37..06a8df4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,17 +28,17 @@ h() {{ } struct SrcRoot + AsRef> { - path: T, + root_path: T, } impl + AsRef> SrcRoot { - fn clone_repo(&self, url: &Url) -> Result<()> { + fn clone_repo(url: &Url, destination: &Path) -> Result<()> { let url = OsString::from(url.as_ref()); Command::new("git") .args([ OsString::from("clone").as_os_str(), url.as_os_str(), - self.path.as_ref(), + destination.as_os_str(), ]) .status()?; Ok(()) @@ -46,7 +46,7 @@ impl + AsRef> SrcRoot { fn as_repo_path(&self, url: &Url) -> PathBuf { let mut dir = PathBuf::new(); - dir.push::<&Path>(self.path.as_ref()); + dir.push::<&Path>(self.root_path.as_ref()); dir.push(url.host_str().unwrap_or("misc")); url.path_segments() .into_iter() @@ -58,15 +58,15 @@ impl + AsRef> SrcRoot { fn ensure_repo_checkout(&self, url: &Url) -> Result { let repo_path = self.as_repo_path(url); - if !repo_path.is_dir() || repo_path.read_dir()?.next().is_none() { + if !repo_path.is_dir() { create_dir_all(&repo_path)?; - self.clone_repo(url)?; } + Self::clone_repo(url, &repo_path)?; Ok(repo_path) } fn search_repo>(&self, slug: S) -> Result> { - let walker = WalkDir::new(&self.path) + let walker = WalkDir::new(&self.root_path) .follow_links(false) .max_depth(MAX_DEPTH) .follow_root_links(false) @@ -91,7 +91,7 @@ impl + AsRef> SrcRoot { } fn new(path: T) -> Self { - Self { path } + Self { root_path: path } } }