mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
appmgr: update tokio tar to v3
This commit is contained in:
committed by
Keagan McClelland
parent
431ff86647
commit
7b0f99881b
@@ -2,7 +2,6 @@ use std::path::Path;
|
||||
|
||||
use failure::ResultExt as _;
|
||||
use futures::stream::StreamExt;
|
||||
use tokio_compat_02::IoCompat;
|
||||
use tokio_tar as tar;
|
||||
|
||||
use crate::config::{ConfigRuleEntry, ConfigSpec};
|
||||
@@ -49,7 +48,7 @@ pub async fn info_full<P: AsRef<Path>>(
|
||||
.with_context(|e| format!("{}: {}", p.display(), e))
|
||||
.with_code(crate::error::FILESYSTEM_ERROR)?;
|
||||
log::info!("Extracting archive.");
|
||||
let mut pkg = tar::Archive::new(IoCompat::new(r));
|
||||
let mut pkg = tar::Archive::new(r);
|
||||
let mut entries = pkg.entries()?;
|
||||
log::info!("Opening manifest from archive.");
|
||||
let manifest = entries
|
||||
@@ -63,7 +62,7 @@ pub async fn info_full<P: AsRef<Path>>(
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing manifest.");
|
||||
let manifest: Manifest = from_cbor_async_reader(IoCompat::new(manifest)).await?;
|
||||
let manifest: Manifest = from_cbor_async_reader(manifest).await?;
|
||||
let manifest = manifest.into_latest();
|
||||
crate::ensure_code!(
|
||||
crate::version::Current::new()
|
||||
@@ -94,7 +93,7 @@ pub async fn info_full<P: AsRef<Path>>(
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing config spec.");
|
||||
let spec = from_cbor_async_reader(IoCompat::new(spec)).await?;
|
||||
let spec = from_cbor_async_reader(spec).await?;
|
||||
log::info!("Opening config rules from archive.");
|
||||
let rules = entries
|
||||
.next()
|
||||
@@ -109,7 +108,7 @@ pub async fn info_full<P: AsRef<Path>>(
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing config rules.");
|
||||
let rules = from_cbor_async_reader(IoCompat::new(rules)).await?;
|
||||
let rules = from_cbor_async_reader(rules).await?;
|
||||
Some(AppConfig { spec, rules })
|
||||
} else {
|
||||
None
|
||||
@@ -125,7 +124,7 @@ pub async fn print_instructions<P: AsRef<Path>>(path: P) -> Result<(), Error> {
|
||||
.with_context(|e| format!("{}: {}", p.display(), e))
|
||||
.with_code(crate::error::FILESYSTEM_ERROR)?;
|
||||
log::info!("Extracting archive.");
|
||||
let mut pkg = tar::Archive::new(IoCompat::new(r));
|
||||
let mut pkg = tar::Archive::new(r);
|
||||
let mut entries = pkg.entries()?;
|
||||
log::info!("Opening manifest from archive.");
|
||||
let manifest = entries
|
||||
@@ -139,7 +138,7 @@ pub async fn print_instructions<P: AsRef<Path>>(path: P) -> Result<(), Error> {
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing manifest.");
|
||||
let manifest: Manifest = from_cbor_async_reader(IoCompat::new(manifest)).await?;
|
||||
let manifest: Manifest = from_cbor_async_reader(manifest).await?;
|
||||
let manifest = manifest.into_latest();
|
||||
crate::ensure_code!(
|
||||
crate::version::Current::new()
|
||||
@@ -167,7 +166,7 @@ pub async fn print_instructions<P: AsRef<Path>>(path: P) -> Result<(), Error> {
|
||||
if manifest.has_instructions {
|
||||
use tokio::io::AsyncWriteExt;
|
||||
|
||||
let instructions = entries
|
||||
let mut instructions = entries
|
||||
.next()
|
||||
.await
|
||||
.ok_or(crate::install::Error::CorruptedPkgFile(
|
||||
@@ -176,7 +175,7 @@ pub async fn print_instructions<P: AsRef<Path>>(path: P) -> Result<(), Error> {
|
||||
.no_code()??;
|
||||
|
||||
let mut stdout = tokio::io::stdout();
|
||||
tokio::io::copy(&mut IoCompat::new(instructions), &mut stdout)
|
||||
tokio::io::copy(&mut instructions, &mut stdout)
|
||||
.await
|
||||
.with_code(crate::error::FILESYSTEM_ERROR)?;
|
||||
stdout
|
||||
|
||||
@@ -16,7 +16,7 @@ use futures::stream::StreamExt;
|
||||
use futures::stream::TryStreamExt;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::io::{AsyncRead, ReadBuf};
|
||||
use tokio_compat_02::{FutureExt, IoCompat};
|
||||
use tokio_compat_02::FutureExt;
|
||||
use tokio_tar as tar;
|
||||
|
||||
use crate::config::{ConfigRuleEntry, ConfigSpec};
|
||||
@@ -215,7 +215,7 @@ pub async fn install<R: AsyncRead + Unpin + Send + Sync>(
|
||||
name: Option<&str>,
|
||||
) -> Result<(), crate::Error> {
|
||||
log::info!("Extracting archive.");
|
||||
let mut pkg = tar::Archive::new(IoCompat::new(r));
|
||||
let mut pkg = tar::Archive::new(r);
|
||||
let mut entries = pkg.entries()?;
|
||||
log::info!("Opening manifest from archive.");
|
||||
let manifest = entries
|
||||
@@ -229,9 +229,7 @@ pub async fn install<R: AsyncRead + Unpin + Send + Sync>(
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing manifest.");
|
||||
let manifest: Manifest = from_cbor_async_reader(IoCompat::new(manifest))
|
||||
.await
|
||||
.no_code()?;
|
||||
let manifest: Manifest = from_cbor_async_reader(manifest).await.no_code()?;
|
||||
match manifest {
|
||||
Manifest::V0(m) => install_v0(m, entries, name).await?,
|
||||
};
|
||||
@@ -240,7 +238,7 @@ pub async fn install<R: AsyncRead + Unpin + Send + Sync>(
|
||||
|
||||
pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
manifest: ManifestV0,
|
||||
mut entries: tar::Entries<IoCompat<R>>,
|
||||
mut entries: tar::Entries<R>,
|
||||
name: Option<&str>,
|
||||
) -> Result<(), crate::Error> {
|
||||
crate::ensure_code!(
|
||||
@@ -295,7 +293,7 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing config spec.");
|
||||
let config_spec: ConfigSpec = from_cbor_async_reader(IoCompat::new(config_spec)).await?;
|
||||
let config_spec: ConfigSpec = from_cbor_async_reader(config_spec).await?;
|
||||
log::info!("Saving config spec.");
|
||||
let mut config_spec_out = app_dir.join("config_spec.yaml").write(None).await?;
|
||||
to_yaml_async_writer(&mut *config_spec_out, &config_spec).await?;
|
||||
@@ -312,15 +310,14 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
"Package File Invalid or Corrupted"
|
||||
);
|
||||
log::trace!("Deserializing config rules.");
|
||||
let config_rules: Vec<ConfigRuleEntry> =
|
||||
from_cbor_async_reader(IoCompat::new(config_rules)).await?;
|
||||
let config_rules: Vec<ConfigRuleEntry> = from_cbor_async_reader(config_rules).await?;
|
||||
log::info!("Saving config rules.");
|
||||
let mut config_rules_out = app_dir.join("config_rules.yaml").write(None).await?;
|
||||
to_yaml_async_writer(&mut *config_rules_out, &config_rules).await?;
|
||||
config_rules_out.commit().await?;
|
||||
if manifest.has_instructions {
|
||||
log::info!("Opening instructions from archive.");
|
||||
let instructions = entries
|
||||
let mut instructions = entries
|
||||
.next()
|
||||
.await
|
||||
.ok_or(Error::CorruptedPkgFile("missing config rules"))
|
||||
@@ -332,7 +329,7 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
);
|
||||
log::info!("Saving instructions.");
|
||||
let mut instructions_out = app_dir.join("instructions.md").write(None).await?;
|
||||
tokio::io::copy(&mut IoCompat::new(instructions), &mut *instructions_out)
|
||||
tokio::io::copy(&mut instructions, &mut *instructions_out)
|
||||
.await
|
||||
.with_code(crate::error::FILESYSTEM_ERROR)?;
|
||||
instructions_out.commit().await?;
|
||||
@@ -373,7 +370,7 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
.with_code(crate::error::FILESYSTEM_ERROR)?;
|
||||
}
|
||||
}
|
||||
src.unpack_in(&dst_path).compat().await?;
|
||||
src.unpack_in(&dst_path).await?;
|
||||
if src.header().entry_type().is_dir() {
|
||||
loop {
|
||||
let mut file = entries
|
||||
@@ -387,7 +384,7 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
{
|
||||
break;
|
||||
} else {
|
||||
file.unpack_in(&dst_path).compat().await?;
|
||||
file.unpack_in(&dst_path).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,7 +430,7 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
)
|
||||
}
|
||||
log::info!("Opening image.tar from archive.");
|
||||
let image = entries
|
||||
let mut image = entries
|
||||
.next()
|
||||
.await
|
||||
.ok_or(Error::CorruptedPkgFile("missing image.tar"))
|
||||
@@ -459,7 +456,7 @@ pub async fn install_v0<R: AsyncRead + Unpin + Send + Sync>(
|
||||
})
|
||||
.spawn()?;
|
||||
let mut child_in = child.stdin.take().unwrap();
|
||||
tokio::io::copy(&mut IoCompat::new(image), &mut child_in).await?;
|
||||
tokio::io::copy(&mut image, &mut child_in).await?;
|
||||
child_in.flush().await?;
|
||||
child_in.shutdown().await?;
|
||||
drop(child_in);
|
||||
|
||||
@@ -5,7 +5,6 @@ use failure::ResultExt;
|
||||
use futures::stream::StreamExt;
|
||||
use linear_map::LinearMap;
|
||||
use rand::SeedableRng;
|
||||
use tokio_compat_02::IoCompat;
|
||||
use tokio_tar as tar;
|
||||
|
||||
use crate::config::{ConfigRuleEntry, ConfigSpec};
|
||||
@@ -42,7 +41,7 @@ pub async fn pack(path: &str, output: &str) -> Result<(), failure::Error> {
|
||||
output.display(),
|
||||
);
|
||||
let out_file = tokio::fs::File::create(output).await?;
|
||||
let mut out = tar::Builder::new(IoCompat::new(out_file));
|
||||
let mut out = tar::Builder::new(out_file);
|
||||
log::info!("Reading {}/manifest.yaml.", path.display());
|
||||
let manifest: Manifest = crate::util::from_yaml_async_reader(
|
||||
tokio::fs::File::open(path.join("manifest.yaml"))
|
||||
@@ -131,7 +130,7 @@ pub async fn pack(path: &str, output: &str) -> Result<(), failure::Error> {
|
||||
h.set_size(0);
|
||||
h.set_path(format!("APPMGR_DIR_END:{}", asset.src.display()))?;
|
||||
h.set_cksum();
|
||||
out.append(&h, IoCompat::new(tokio::io::empty())).await?;
|
||||
out.append(&h, tokio::io::empty()).await?;
|
||||
} else {
|
||||
out.append_path_with_name(&file_path, &asset.src).await?;
|
||||
}
|
||||
@@ -145,8 +144,7 @@ pub async fn pack(path: &str, output: &str) -> Result<(), failure::Error> {
|
||||
log::info!("Writing image.tar to archive.");
|
||||
let mut header = tar::Header::new_gnu();
|
||||
header.set_size(image.metadata().await?.len());
|
||||
out.append_data(&mut header, "image.tar", IoCompat::new(image))
|
||||
.await?;
|
||||
out.append_data(&mut header, "image.tar", image).await?;
|
||||
}
|
||||
}
|
||||
out.into_inner().await?;
|
||||
@@ -201,7 +199,7 @@ pub async fn verify(path: &str) -> Result<(), failure::Error> {
|
||||
.await
|
||||
.with_context(|e| format!("{}: {}", path.display(), e))?;
|
||||
log::info!("Extracting archive.");
|
||||
let mut pkg = tar::Archive::new(IoCompat::new(r));
|
||||
let mut pkg = tar::Archive::new(r);
|
||||
let mut entries = pkg.entries()?;
|
||||
log::info!("Opening manifest from archive.");
|
||||
let manifest = entries
|
||||
@@ -214,7 +212,7 @@ pub async fn verify(path: &str) -> Result<(), failure::Error> {
|
||||
manifest.path()?.display()
|
||||
);
|
||||
log::trace!("Deserializing manifest.");
|
||||
let manifest: Manifest = from_cbor_async_reader(IoCompat::new(manifest)).await?;
|
||||
let manifest: Manifest = from_cbor_async_reader(manifest).await?;
|
||||
let manifest = manifest.into_latest();
|
||||
ensure!(
|
||||
crate::version::Current::new()
|
||||
@@ -247,7 +245,7 @@ pub async fn verify(path: &str) -> Result<(), failure::Error> {
|
||||
config_spec.path()?.display()
|
||||
);
|
||||
log::trace!("Deserializing config spec.");
|
||||
let config_spec: ConfigSpec = from_cbor_async_reader(IoCompat::new(config_spec)).await?;
|
||||
let config_spec: ConfigSpec = from_cbor_async_reader(config_spec).await?;
|
||||
log::trace!("Validating config spec.");
|
||||
config_spec.validate(&manifest)?;
|
||||
let config = config_spec.gen(&mut rand::rngs::StdRng::from_entropy(), &None)?;
|
||||
@@ -263,8 +261,7 @@ pub async fn verify(path: &str) -> Result<(), failure::Error> {
|
||||
config_rules.path()?.display()
|
||||
);
|
||||
log::trace!("Deserializing config rules.");
|
||||
let config_rules: Vec<ConfigRuleEntry> =
|
||||
from_cbor_async_reader(IoCompat::new(config_rules)).await?;
|
||||
let config_rules: Vec<ConfigRuleEntry> = from_cbor_async_reader(config_rules).await?;
|
||||
log::trace!("Validating config rules against config spec.");
|
||||
let mut cfgs = LinearMap::new();
|
||||
cfgs.insert(name, Cow::Borrowed(&config));
|
||||
@@ -378,7 +375,7 @@ pub async fn verify(path: &str) -> Result<(), failure::Error> {
|
||||
.await
|
||||
.ok_or_else(|| format_err!("image.tar is missing manifest.json"))??;
|
||||
let image_manifest: Vec<DockerManifest> =
|
||||
from_json_async_reader(IoCompat::new(image_manifest)).await?;
|
||||
from_json_async_reader(image_manifest).await?;
|
||||
image_manifest
|
||||
.into_iter()
|
||||
.flat_map(|a| a.repo_tags)
|
||||
|
||||
Reference in New Issue
Block a user