Skip to content

Commit dddb8df

Browse files
committed
Switch from async-tar to uh sync tar uh
Signed-off-by: itowlson <[email protected]>
1 parent f0eb00c commit dddb8df

File tree

3 files changed

+49
-153
lines changed

3 files changed

+49
-153
lines changed

Cargo.lock

Lines changed: 6 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/oci/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ edition = { workspace = true }
77
[dependencies]
88
anyhow = { workspace = true }
99
async-compression = { version = "0.4", features = ["gzip", "tokio"] }
10-
async-tar = "0.5"
1110
base64 = { workspace = true }
1211
chrono = { workspace = true }
1312
# Fork with updated auth to support ACR login
1413
# Ref https://github.com/camallo/dkregistry-rs/pull/263
1514
dirs = { workspace = true }
1615
dkregistry = { git = "https://github.com/fermyon/dkregistry-rs", rev = "161cf2b66996ed97c7abaf046e38244484814de3" }
1716
docker_credential = "1"
17+
flate2 = { workspace = true }
1818
futures-util = { workspace = true }
1919
itertools = { workspace = true }
2020
oci-distribution = { git = "https://github.com/fermyon/oci-distribution", rev = "7b291a39f74d1a3c9499d934a56cae6580fc8e37" }
@@ -25,6 +25,7 @@ spin-common = { path = "../common" }
2525
spin-compose = { path = "../compose" }
2626
spin-loader = { path = "../loader" }
2727
spin-locked-app = { path = "../locked-app" }
28+
tar = "0.4"
2829
tempfile = { workspace = true }
2930
tokio = { workspace = true, features = ["fs"] }
3031
tokio-util = { version = "0.7", features = ["compat"] }

crates/oci/src/utils.rs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,59 @@
11
//! Utilities related to distributing Spin apps via OCI registries
22
33
use anyhow::{Context, Result};
4-
use async_compression::tokio::bufread::GzipDecoder;
5-
use async_compression::tokio::write::GzipEncoder;
6-
use async_tar::Archive;
4+
use flate2::read::GzDecoder;
5+
use flate2::write::GzEncoder;
76
use spin_common::ui::quoted_path;
87
use std::path::{Path, PathBuf};
8+
use tar::Archive;
99

1010
/// Create a compressed archive of source, returning its path in working_dir
1111
pub async fn archive(source: &Path, working_dir: &Path) -> Result<PathBuf> {
12-
// Create tar archive file
13-
let tar_gz_path = working_dir
14-
.join(source.file_name().unwrap())
15-
.with_extension("tar.gz");
16-
let tar_gz = tokio::fs::File::create(tar_gz_path.as_path())
17-
.await
18-
.context(format!(
12+
let source = source.to_owned();
13+
let working_dir = working_dir.to_owned();
14+
15+
tokio::task::spawn_blocking(move || {
16+
// Create tar archive file
17+
let tar_gz_path = working_dir
18+
.join(source.file_name().unwrap())
19+
.with_extension("tar.gz");
20+
let tar_gz = std::fs::File::create(tar_gz_path.as_path()).context(format!(
1921
"Unable to create tar archive for source {}",
20-
quoted_path(source)
22+
quoted_path(&source)
2123
))?;
2224

23-
// Create encoder
24-
// TODO: use zstd? May be more performant
25-
let tar_gz_enc = GzipEncoder::new(tar_gz);
26-
27-
// Build tar archive
28-
let mut tar_builder = async_tar::Builder::new(
29-
tokio_util::compat::TokioAsyncWriteCompatExt::compat_write(tar_gz_enc),
30-
);
31-
tar_builder
32-
.append_dir_all(".", source)
33-
.await
34-
.context(format!(
25+
// Create encoder
26+
// TODO: use zstd? May be more performant
27+
let tar_gz_enc = GzEncoder::new(tar_gz, flate2::Compression::default());
28+
29+
// Build tar archive
30+
let mut tar_builder = tar::Builder::new(tar_gz_enc);
31+
tar_builder.append_dir_all(".", &source).context(format!(
3532
"Unable to create tar archive for source {}",
36-
quoted_path(source)
33+
quoted_path(&source)
3734
))?;
38-
// Finish writing the archive
39-
tar_builder.finish().await?;
40-
// Shutdown the encoder
41-
use tokio::io::AsyncWriteExt;
42-
tar_builder
43-
.into_inner()
44-
.await?
45-
.into_inner()
46-
.shutdown()
47-
.await?;
48-
Ok(tar_gz_path)
35+
36+
// Finish writing the archive and shut down the encoder.
37+
let inner_enc = tar_builder.into_inner()?;
38+
inner_enc.finish()?;
39+
40+
Ok(tar_gz_path)
41+
})
42+
.await?
4943
}
5044

5145
/// Unpack a compressed archive existing at source into dest
5246
pub async fn unarchive(source: &Path, dest: &Path) -> Result<()> {
53-
let decoder = GzipDecoder::new(tokio::io::BufReader::new(
54-
tokio::fs::File::open(source).await?,
55-
));
56-
let archive = Archive::new(tokio_util::compat::TokioAsyncReadCompatExt::compat(decoder));
57-
if let Err(e) = archive.unpack(dest).await {
58-
return Err(e.into());
59-
};
60-
Ok(())
47+
let source = source.to_owned();
48+
let dest = dest.to_owned();
49+
50+
tokio::task::spawn_blocking(move || {
51+
let decoder = GzDecoder::new(std::fs::File::open(&source)?);
52+
let mut archive = Archive::new(decoder);
53+
if let Err(e) = archive.unpack(&dest) {
54+
return Err(e.into());
55+
};
56+
Ok(())
57+
})
58+
.await?
6159
}

0 commit comments

Comments
 (0)