fix: clone into proper destination
This commit is contained in:
parent
7024c45a04
commit
430d988f31
1 changed files with 8 additions and 8 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -28,17 +28,17 @@ h() {{
|
|||
}
|
||||
|
||||
struct SrcRoot<T: AsRef<Path> + AsRef<OsStr>> {
|
||||
path: T,
|
||||
root_path: T,
|
||||
}
|
||||
|
||||
impl<T: AsRef<Path> + AsRef<OsStr>> SrcRoot<T> {
|
||||
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<T: AsRef<Path> + AsRef<OsStr>> SrcRoot<T> {
|
|||
|
||||
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<T: AsRef<Path> + AsRef<OsStr>> SrcRoot<T> {
|
|||
|
||||
fn ensure_repo_checkout(&self, url: &Url) -> Result<PathBuf> {
|
||||
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<S: AsRef<OsStr>>(&self, slug: S) -> Result<Option<PathBuf>> {
|
||||
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<T: AsRef<Path> + AsRef<OsStr>> SrcRoot<T> {
|
|||
}
|
||||
|
||||
fn new(path: T) -> Self {
|
||||
Self { path }
|
||||
Self { root_path: path }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue