seed: more atomic
This commit is contained in:
@@ -159,7 +159,7 @@ async fn seed_config(
|
||||
let cfg_path = &format!("{base_dir}/config.yaml");
|
||||
|
||||
if fs::try_exists(cfg_path).await? {
|
||||
return Ok(fs::read(cfg_path).await?);
|
||||
return verifier.verify_path(&cfg_path).await;
|
||||
}
|
||||
|
||||
let bs_tar = "/bootstrap.tar";
|
||||
@@ -172,13 +172,20 @@ async fn seed_config(
|
||||
fetch_bootstrap(bs, bs_tar).await?;
|
||||
}
|
||||
|
||||
try_exec("tar", &["xf", bs_tar, "-C", base_dir]).await?;
|
||||
let tmp_dir = &format!("{base_dir}.new");
|
||||
fs::create_dir_all(tmp_dir).await?;
|
||||
|
||||
try_exec("tar", &["xf", bs_tar, "-C", tmp_dir]).await?;
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
verifier.verify_path(&cfg_path).await
|
||||
let cfg_bytes = verifier.verify_path(&cfg_path).await?;
|
||||
|
||||
fs::rename(tmp_dir, base_dir).await?;
|
||||
Ok(cfg_bytes)
|
||||
}
|
||||
|
||||
async fn fetch_bootstrap(bs: &dkl::bootstrap::Bootstrap, output_file: &str) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user