Skip to content

Commit 1396d53

Browse files
committed
composefs/state: Copy /var from image to fresh installations
Signed-off-by: Chaser Huang <huangkangjing@gmail.com>
1 parent 0aae35a commit 1396d53

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

crates/lib/src/bootc_composefs/state.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ pub(crate) fn get_booted_bls(boot_dir: &Dir) -> Result<BLSConfig> {
7676
Err(anyhow::anyhow!("Booted BLS not found"))
7777
}
7878

79-
/// Mounts an EROFS image and copies the pristine /etc to the deployment's /etc
80-
#[context("Copying etc")]
81-
pub(crate) fn copy_etc_to_state(
79+
/// Mounts an EROFS image and copies the pristine /etc and /var to the deployment's /etc and /var.
80+
/// Only copies /var for initial installation of deployments (non-staged deployments)
81+
#[context("Initializing /etc and /var for state")]
82+
pub(crate) fn initialize_state(
8283
sysroot_path: &Utf8PathBuf,
8384
erofs_id: &String,
8485
state_path: &Utf8PathBuf,
86+
initialize_var: bool
8587
) -> Result<()> {
8688
let sysroot_fd = open(
8789
sysroot_path.as_std_path(),
@@ -95,6 +97,17 @@ pub(crate) fn copy_etc_to_state(
9597
let tempdir = TempMount::mount_fd(composefs_fd)?;
9698

9799
// TODO: Replace this with a function to cap_std_ext
100+
if initialize_var {
101+
Command::new("cp")
102+
.args([
103+
"-a",
104+
"--remove-destination",
105+
&format!("{}/var/.", tempdir.dir.path().as_str()?),
106+
&format!("{state_path}/var/."),
107+
])
108+
.run_capture_stderr()?;
109+
}
110+
98111
let cp_ret = Command::new("cp")
99112
.args([
100113
"-a",
@@ -225,8 +238,6 @@ pub(crate) async fn write_composefs_state(
225238

226239
create_dir_all(state_path.join("etc"))?;
227240

228-
copy_etc_to_state(&root_path, &deployment_id.to_hex(), &state_path)?;
229-
230241
let actual_var_path = root_path.join(SHARED_VAR_PATH);
231242
create_dir_all(&actual_var_path)?;
232243

@@ -237,6 +248,8 @@ pub(crate) async fn write_composefs_state(
237248
)
238249
.context("Failed to create symlink for /var")?;
239250

251+
initialize_state(&root_path, &deployment_id.to_hex(), &state_path, !staged)?;
252+
240253
let ImageReference {
241254
image: image_name,
242255
transport,

0 commit comments

Comments
 (0)