Skip to content

Commit

Permalink
Merge pull request #183 from helsing-ai/mara/clear-vendor
Browse files Browse the repository at this point in the history
Clear the proto store before installing dependencies
  • Loading branch information
mara-schulke authored Dec 6, 2023
2 parents faef703 + fa2cf24 commit 0ccb355
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ pub async fn install() -> miette::Result<()> {
let store = PackageStore::current().await?;
let credentials = Credentials::load().await?;

store.clear().await?;
store.populate(&manifest).await?;

let dependency_graph =
Expand Down
15 changes: 9 additions & 6 deletions src/package/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl PackageStore {
}

/// Path to where the package contents are populated.
pub fn populated_path(&self, manifest: &Manifest) -> PathBuf {
fn populated_path(&self, manifest: &Manifest) -> PathBuf {
self.proto_vendor_path()
.join(manifest.package.name.to_string())
}
Expand All @@ -101,13 +101,16 @@ impl PackageStore {
/// Clears all packages from the file system
pub async fn clear(&self) -> miette::Result<()> {
let path = self.proto_vendor_path();

match fs::remove_dir_all(&path).await {
Ok(()) => Ok(()),
Err(err) if matches!(err.kind(), std::io::ErrorKind::NotFound) => {
Err(miette!("directory {path:?} not found"))
}
Err(_) => Err(miette!("failed to clear {path:?} directory",)),
Ok(()) => {}
Err(err) if matches!(err.kind(), std::io::ErrorKind::NotFound) => {}
Err(_) => return Err(miette!("failed to clear {path:?} directory",)),
}

fs::create_dir(&path)
.await
.map_err(|_| miette!("failed to reinitialize {path:?} directory after cleaning"))
}

/// Unpacks a package into a local directory
Expand Down

0 comments on commit 0ccb355

Please sign in to comment.