untar by ourselves

This commit is contained in:
Mikaël Cluseau
2026-06-04 19:08:54 +02:00
parent 3036b2f417
commit d4ec6380f8
3 changed files with 54 additions and 12 deletions
+32 -12
View File
@@ -152,34 +152,42 @@ impl Verifier {
}
async fn seed_config(
base_dir: &str,
base_dir: impl Into<PathBuf>,
bs: &dkl::bootstrap::Bootstrap,
verifier: &Verifier,
) -> Result<Vec<u8>> {
let cfg_path = &format!("{base_dir}/config.yaml");
let base_dir = base_dir.into();
if fs::try_exists(cfg_path).await? {
return verifier.verify_path(&cfg_path).await;
let cfg_path = base_dir.join("config.yaml");
if fs::try_exists(&cfg_path).await? {
return verifier.verify_path(cfg_path).await;
}
let bs_tar = "/bootstrap.tar";
if !fs::try_exists(bs_tar).await? {
if !fs::try_exists(&bs_tar).await? {
if bs.seed.is_none() {
return Err(format_err!(
"no {cfg_path}, no {bs_tar} and no seed URL, can't bootstrap"
"no {}, no {bs_tar} and no seed URL, can't bootstrap",
cfg_path.display()
));
}
fetch_bootstrap(bs, bs_tar).await?;
}
let tmp_dir = &format!("{base_dir}.new");
fs::create_dir_all(tmp_dir).await?;
let tmp_dir = base_dir.with_added_extension("new");
fs::create_dir_all(&tmp_dir).await?;
try_exec("tar", &["xf", bs_tar, "-C", tmp_dir]).await?;
untar(bs_tar, &tmp_dir)
.await
.map_err(|e| format_err!("untar failed: {e}"))?;
let cfg_path = &format!("{tmp_dir}/config.yaml");
if !fs::try_exists(cfg_path).await? {
return Err(format_err!("{cfg_path} does not exist after seeding"));
let cfg_path = tmp_dir.join("config.yaml");
if !fs::try_exists(&cfg_path).await? {
return Err(format_err!(
"{} does not exist after seeding",
cfg_path.display()
));
}
let cfg_bytes = verifier.verify_path(&cfg_path).await?;
@@ -236,6 +244,18 @@ async fn fetch_bootstrap(bs: &dkl::bootstrap::Bootstrap, output_file: &str) -> R
Ok(())
}
async fn untar(arch: impl Into<PathBuf>, target: impl Into<PathBuf>) -> Result<()> {
let arch = arch.into();
let target = target.into();
tokio::task::spawn_blocking(move || {
let tar = std::fs::File::open(arch)?;
let mut tar = tar::Archive::new(tar);
tar.unpack(target)
})
.await??;
Ok(())
}
fn default_root_tmpfs_opts() -> Option<String> {
let mem = sys_info::mem_info()
.inspect_err(|e| warn!("failed to get system memory info, using default tmpfs size: {e}"))