Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear the proto store before installing dependencies #183

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?;
tomkarw marked this conversation as resolved.
Show resolved Hide resolved
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