diff --git a/tufaceous-lib/Cargo.toml b/tufaceous-lib/Cargo.toml index 92ae34d4a1..0df3a33f98 100644 --- a/tufaceous-lib/Cargo.toml +++ b/tufaceous-lib/Cargo.toml @@ -30,6 +30,7 @@ serde_path_to_error.workspace = true sha2.workspace = true slog.workspace = true tar.workspace = true +tokio.workspace = true toml.workspace = true tough.workspace = true url = "2.4.1" diff --git a/tufaceous-lib/src/repository.rs b/tufaceous-lib/src/repository.rs index 9b4f079b00..416d5c9990 100644 --- a/tufaceous-lib/src/repository.rs +++ b/tufaceous-lib/src/repository.rs @@ -89,7 +89,8 @@ impl OmicronRepo { let log = log.new(slog::o!("component" => "OmicronRepo")); let repo_path = repo_path.canonicalize_utf8()?; let root_json = repo_path.join("metadata").join("1.root.json"); - let root = std::fs::read(&root_json) + let root = tokio::fs::read(&root_json) + .await .with_context(|| format!("error reading from {root_json}"))?; let repo = RepositoryLoader::new( diff --git a/wicketd/src/artifacts/artifacts_with_plan.rs b/wicketd/src/artifacts/artifacts_with_plan.rs index 01513b6f5e..d3319d7f6b 100644 --- a/wicketd/src/artifacts/artifacts_with_plan.rs +++ b/wicketd/src/artifacts/artifacts_with_plan.rs @@ -223,6 +223,9 @@ mod tests { /// Test that `ArtifactsWithPlan` can extract the fake repository generated /// by tufaceous. + /// + /// See documentation for extract_nested_artifact_pair in update_plan.rs + /// for why multi_thread is required. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_extract_fake() -> Result<()> { let logctx = test_setup_log("test_extract_fake"); diff --git a/wicketd/src/artifacts/extracted_artifacts.rs b/wicketd/src/artifacts/extracted_artifacts.rs index 6be9c95661..5683cd1c13 100644 --- a/wicketd/src/artifacts/extracted_artifacts.rs +++ b/wicketd/src/artifacts/extracted_artifacts.rs @@ -16,12 +16,11 @@ use sha2::Digest; use sha2::Sha256; use slog::info; use slog::Logger; -use std::fs::File; use std::io; -use std::io::BufWriter; use std::io::Write; use std::sync::Arc; use tokio::io::AsyncRead; +use tokio::io::AsyncWriteExt; use tokio_util::io::ReaderStream; /// Handle to the data of an extracted artifact. @@ -124,7 +123,7 @@ impl ExtractedArtifacts { self.tempdir.path().join(format!("{}", artifact_hash_id.hash)) } - /// Copy from `reader` into our temp directory, returning a handle to the + /// Copy from `stream` into our temp directory, returning a handle to the /// extracted artifact on success. pub(super) async fn store( &mut self, @@ -133,8 +132,9 @@ impl ExtractedArtifacts { ) -> Result { let output_path = self.path_for_artifact(&artifact_hash_id); - let mut writer = BufWriter::new( - File::create(&output_path) + let mut writer = tokio::io::BufWriter::new( + tokio::fs::File::create(&output_path) + .await .with_context(|| { format!("failed to create temp file {output_path}") }) @@ -156,6 +156,7 @@ impl ExtractedArtifacts { file_size += chunk.len(); writer .write_all(&chunk) + .await .with_context(|| format!("failed writing to {output_path}")) .map_err(|error| RepositoryError::CopyExtractedArtifact { kind: artifact_hash_id.kind.clone(), @@ -165,6 +166,7 @@ impl ExtractedArtifacts { writer .flush() + .await .with_context(|| format!("failed flushing {output_path}")) .map_err(|error| RepositoryError::CopyExtractedArtifact { kind: artifact_hash_id.kind.clone(), diff --git a/wicketd/src/artifacts/update_plan.rs b/wicketd/src/artifacts/update_plan.rs index 9b136e4ebe..c6db7c1b65 100644 --- a/wicketd/src/artifacts/update_plan.rs +++ b/wicketd/src/artifacts/update_plan.rs @@ -938,6 +938,8 @@ mod tests { builder.build_to_vec().unwrap() } + // See documentation for extract_nested_artifact_pair for why multi_thread + // is required. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_update_plan_from_artifacts() { const VERSION_0: SemverVersion = SemverVersion::new(0, 0, 0); diff --git a/wicketd/tests/integration_tests/updates.rs b/wicketd/tests/integration_tests/updates.rs index 4d2bdcf28e..b65833a74b 100644 --- a/wicketd/tests/integration_tests/updates.rs +++ b/wicketd/tests/integration_tests/updates.rs @@ -31,6 +31,8 @@ use wicketd_client::types::{ StartUpdateParams, }; +// See documentation for extract_nested_artifact_pair in update_plan.rs for why +// multi_thread is required. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_updates() { let gateway = gateway_setup::test_setup("test_updates", SpPort::One).await; @@ -258,6 +260,8 @@ async fn test_updates() { wicketd_testctx.teardown().await; } +// See documentation for extract_nested_artifact_pair in update_plan.rs for why +// multi_thread is required. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_installinator_fetch() { let gateway = gateway_setup::test_setup("test_updates", SpPort::One).await; @@ -391,6 +395,8 @@ async fn test_installinator_fetch() { wicketd_testctx.teardown().await; } +// See documentation for extract_nested_artifact_pair in update_plan.rs for why +// multi_thread is required. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_update_races() { let gateway = gateway_setup::test_setup(