@@ -107,6 +107,37 @@ pub(crate) fn copy_etc_to_state(
107107 cp_ret
108108}
109109
110+ /// Mounts an EROFS image and copies the pristine /var to the deployment's /var
111+ #[ context( "Copying var" ) ]
112+ pub ( crate ) fn copy_var_to_state (
113+ sysroot_path : & Utf8PathBuf ,
114+ erofs_id : & String ,
115+ state_path : & Utf8PathBuf ,
116+ ) -> Result < ( ) > {
117+ let sysroot_fd = open (
118+ sysroot_path. as_std_path ( ) ,
119+ OFlags :: PATH | OFlags :: DIRECTORY | OFlags :: CLOEXEC ,
120+ Mode :: empty ( ) ,
121+ )
122+ . context ( "Opening sysroot" ) ?;
123+
124+ let composefs_fd = bootc_initramfs_setup:: mount_composefs_image ( & sysroot_fd, & erofs_id, false ) ?;
125+
126+ let tempdir = TempMount :: mount_fd ( composefs_fd) ?;
127+
128+ // TODO: Replace this with a function to cap_std_ext
129+ let cp_ret = Command :: new ( "cp" )
130+ . args ( [
131+ "-a" ,
132+ "--remove-destination" ,
133+ & format ! ( "{}/var/." , tempdir. dir. path( ) . as_str( ) ?) ,
134+ & format ! ( "{state_path}/var/." ) ,
135+ ] )
136+ . run_capture_stderr ( ) ;
137+
138+ cp_ret
139+ }
140+
110141/// Adds or updates the provided key/value pairs in the .origin file of the deployment pointed to
111142/// by the `deployment_id`
112143fn add_update_in_origin (
@@ -237,6 +268,10 @@ pub(crate) async fn write_composefs_state(
237268 )
238269 . context ( "Failed to create symlink for /var" ) ?;
239270
271+ if !staged {
272+ copy_var_to_state ( & root_path, & deployment_id. to_hex ( ) , & state_path) ?;
273+ }
274+
240275 let ImageReference {
241276 image : image_name,
242277 transport,
0 commit comments