@@ -2049,7 +2049,8 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
20492049}
20502050
20512051pub ( crate ) const COMPOSEFS_TRANSIENT_STATE_DIR : & str = "/run/composefs" ;
2052- pub ( crate ) const COMPOSEFS_STAGED_DEPLOYMENT_PATH : & str = "/run/composefs/staged-deployment" ;
2052+ /// File created in /run/composefs to record a staged-deployment
2053+ pub ( crate ) const COMPOSEFS_STAGED_DEPLOYMENT_FNAME : & str = "staged-deployment" ;
20532054/// Relative to /sysroot
20542055pub ( crate ) const STATE_DIR_RELATIVE : & str = "state/deploy" ;
20552056
@@ -2091,25 +2092,32 @@ pub(crate) fn write_composefs_state(
20912092 . section ( ORIGIN_KEY_BOOT )
20922093 . item ( ORIGIN_KEY_BOOT_TYPE , boot_type) ;
20932094
2094- let mut origin_file =
2095- std:: fs:: File :: create ( state_path. join ( format ! ( "{}.origin" , deployment_id. to_hex( ) ) ) )
2096- . context ( "Failed to open .origin file" ) ?;
2095+ let state_dir = cap_std:: fs:: Dir :: open_ambient_dir ( & state_path, cap_std:: ambient_authority ( ) )
2096+ . context ( "Opening state dir" ) ?;
20972097
2098- origin_file
2099- . write ( config. to_string ( ) . as_bytes ( ) )
2098+ state_dir
2099+ . atomic_write (
2100+ format ! ( "{}.origin" , deployment_id. to_hex( ) ) ,
2101+ config. to_string ( ) . as_bytes ( ) ,
2102+ )
21002103 . context ( "Falied to write to .origin file" ) ?;
21012104
21022105 if staged {
21032106 std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
21042107 . with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
21052108
2106- let mut file = std :: fs:: OpenOptions :: new ( )
2107- . write ( true )
2108- . create ( true )
2109- . open ( COMPOSEFS_STAGED_DEPLOYMENT_PATH )
2110- . context ( "Opening staged-deployment file" ) ?;
2109+ let staged_depl_dir = cap_std :: fs:: Dir :: open_ambient_dir (
2110+ COMPOSEFS_TRANSIENT_STATE_DIR ,
2111+ cap_std :: ambient_authority ( ) ,
2112+ )
2113+ . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
21112114
2112- file. write_all ( deployment_id. to_hex ( ) . as_bytes ( ) ) ?;
2115+ staged_depl_dir
2116+ . atomic_write (
2117+ COMPOSEFS_STAGED_DEPLOYMENT_FNAME ,
2118+ deployment_id. to_hex ( ) . as_bytes ( ) ,
2119+ )
2120+ . with_context ( || format ! ( "Writing to {COMPOSEFS_STAGED_DEPLOYMENT_FNAME}" ) ) ?;
21132121 }
21142122
21152123 Ok ( ( ) )
0 commit comments