@@ -2052,7 +2052,8 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
2052
2052
}
2053
2053
2054
2054
pub ( crate ) const COMPOSEFS_TRANSIENT_STATE_DIR : & str = "/run/composefs" ;
2055
- pub ( crate ) const COMPOSEFS_STAGED_DEPLOYMENT_PATH : & str = "/run/composefs/staged-deployment" ;
2055
+ /// File created in /run/composefs to record a staged-deployment
2056
+ pub ( crate ) const COMPOSEFS_STAGED_DEPLOYMENT_FNAME : & str = "staged-deployment" ;
2056
2057
/// Relative to /sysroot
2057
2058
pub ( crate ) const STATE_DIR_RELATIVE : & str = "state/deploy" ;
2058
2059
@@ -2094,25 +2095,32 @@ pub(crate) fn write_composefs_state(
2094
2095
. section ( ORIGIN_KEY_BOOT )
2095
2096
. item ( ORIGIN_KEY_BOOT_TYPE , boot_type) ;
2096
2097
2097
- let mut origin_file =
2098
- std:: fs:: File :: create ( state_path. join ( format ! ( "{}.origin" , deployment_id. to_hex( ) ) ) )
2099
- . context ( "Failed to open .origin file" ) ?;
2098
+ let state_dir = cap_std:: fs:: Dir :: open_ambient_dir ( & state_path, cap_std:: ambient_authority ( ) )
2099
+ . context ( "Opening state dir" ) ?;
2100
2100
2101
- origin_file
2102
- . write ( config. to_string ( ) . as_bytes ( ) )
2101
+ state_dir
2102
+ . atomic_write (
2103
+ format ! ( "{}.origin" , deployment_id. to_hex( ) ) ,
2104
+ config. to_string ( ) . as_bytes ( ) ,
2105
+ )
2103
2106
. context ( "Falied to write to .origin file" ) ?;
2104
2107
2105
2108
if staged {
2106
2109
std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
2107
2110
. with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
2108
2111
2109
- let mut file = std :: fs:: OpenOptions :: new ( )
2110
- . write ( true )
2111
- . create ( true )
2112
- . open ( COMPOSEFS_STAGED_DEPLOYMENT_PATH )
2113
- . context ( "Opening staged-deployment file" ) ?;
2112
+ let staged_depl_dir = cap_std :: fs:: Dir :: open_ambient_dir (
2113
+ COMPOSEFS_TRANSIENT_STATE_DIR ,
2114
+ cap_std :: ambient_authority ( ) ,
2115
+ )
2116
+ . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
2114
2117
2115
- file. write_all ( deployment_id. to_hex ( ) . as_bytes ( ) ) ?;
2118
+ staged_depl_dir
2119
+ . atomic_write (
2120
+ COMPOSEFS_STAGED_DEPLOYMENT_FNAME ,
2121
+ deployment_id. to_hex ( ) . as_bytes ( ) ,
2122
+ )
2123
+ . with_context ( || format ! ( "Writing to {COMPOSEFS_STAGED_DEPLOYMENT_FNAME}" ) ) ?;
2116
2124
}
2117
2125
2118
2126
Ok ( ( ) )
0 commit comments