From 0ec0e645a613fc6682be5f146f249eac5504a859 Mon Sep 17 00:00:00 2001 From: Mara Schulke Date: Wed, 6 Dec 2023 11:15:48 +0100 Subject: [PATCH 1/4] Clear the proto store before installing dependencies --- src/command.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command.rs b/src/command.rs index a0bb5e2e..e1851014 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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 = From 38e0327b0bd0d7444bfb5f5da1419cd166beece4 Mon Sep 17 00:00:00 2001 From: Mara Schulke Date: Wed, 6 Dec 2023 11:23:49 +0100 Subject: [PATCH 2/4] Recreate the vendor directory --- src/package/store.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/package/store.rs b/src/package/store.rs index ea931ec6..9154b91d 100644 --- a/src/package/store.rs +++ b/src/package/store.rs @@ -102,7 +102,9 @@ impl PackageStore { pub async fn clear(&self) -> miette::Result<()> { let path = self.proto_vendor_path(); match fs::remove_dir_all(&path).await { - Ok(()) => Ok(()), + Ok(()) => fs::create_dir(&path) + .await + .map_err(|_| miette!("failed to reinitialize {path:?} directory after cleaning")), Err(err) if matches!(err.kind(), std::io::ErrorKind::NotFound) => { Err(miette!("directory {path:?} not found")) } From 90ff6722f6ab3aec6e9e16dee70fc2cc15afb7f5 Mon Sep 17 00:00:00 2001 From: Mara Schulke Date: Wed, 6 Dec 2023 11:41:32 +0100 Subject: [PATCH 3/4] Ignore errors if the store is not able to be cleared --- src/command.rs | 2 +- src/package/store.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.rs b/src/command.rs index e1851014..45a25e75 100644 --- a/src/command.rs +++ b/src/command.rs @@ -244,7 +244,7 @@ pub async fn install() -> miette::Result<()> { let store = PackageStore::current().await?; let credentials = Credentials::load().await?; - store.clear().await?; + store.clear().await.ok(); store.populate(&manifest).await?; let dependency_graph = diff --git a/src/package/store.rs b/src/package/store.rs index 9154b91d..ef993878 100644 --- a/src/package/store.rs +++ b/src/package/store.rs @@ -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()) } From 639f698c77a57f97c421be6a7bb13e099b54dc99 Mon Sep 17 00:00:00 2001 From: Mara Schulke Date: Wed, 6 Dec 2023 11:43:48 +0100 Subject: [PATCH 4/4] Change the behavior of `clear` --- src/command.rs | 2 +- src/package/store.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/command.rs b/src/command.rs index 45a25e75..e1851014 100644 --- a/src/command.rs +++ b/src/command.rs @@ -244,7 +244,7 @@ pub async fn install() -> miette::Result<()> { let store = PackageStore::current().await?; let credentials = Credentials::load().await?; - store.clear().await.ok(); + store.clear().await?; store.populate(&manifest).await?; let dependency_graph = diff --git a/src/package/store.rs b/src/package/store.rs index ef993878..9fe64fef 100644 --- a/src/package/store.rs +++ b/src/package/store.rs @@ -101,15 +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(()) => fs::create_dir(&path) - .await - .map_err(|_| miette!("failed to reinitialize {path:?} directory after cleaning")), - 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