diff --git a/lib/cli/src/commands/package/download.rs b/lib/cli/src/commands/package/download.rs index 096aa0245ac..36dd8cd48ad 100644 --- a/lib/cli/src/commands/package/download.rs +++ b/lib/cli/src/commands/package/download.rs @@ -107,7 +107,13 @@ impl PackageDownload { .error_for_status() .context("http request failed with non-success status code")?; - let mut tmpfile = tempfile::NamedTempFile::new()?; + let tmp_path = self.out_path.with_extension("webc_tmp"); + let mut tmpfile = std::fs::File::create(&tmp_path).with_context(|| { + format!( + "could not create temporary file at '{}'", + tmp_path.display() + ) + })?; let ty = res .headers() @@ -132,18 +138,20 @@ impl PackageDownload { .context("could not write to temporary file")?; } - tmpfile.as_file_mut().sync_all()?; + tmpfile.sync_all()?; + std::mem::drop(tmpfile); if self.validate { eprintln!("Validating package..."); - webc::compat::Container::from_disk(tmpfile.path()) + webc::compat::Container::from_disk(&tmp_path) .context("could not parse downloaded file as a package - invalid download?")?; eprintln!("Downloaded package is valid!"); } - tmpfile.persist(&self.out_path).with_context(|| { + std::fs::rename(&tmp_path, &self.out_path).with_context(|| { format!( - "could not persist temporary file to '{}'", + "could not move temporary file from '{}' to '{}'", + tmp_path.display(), self.out_path.display() ) })?;