@@ -2049,7 +2049,8 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
2049
2049
}
2050
2050
2051
2051
pub ( 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" ;
2053
2054
/// Relative to /sysroot
2054
2055
pub ( crate ) const STATE_DIR_RELATIVE : & str = "state/deploy" ;
2055
2056
@@ -2091,25 +2092,32 @@ pub(crate) fn write_composefs_state(
2091
2092
. section ( ORIGIN_KEY_BOOT )
2092
2093
. item ( ORIGIN_KEY_BOOT_TYPE , boot_type) ;
2093
2094
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" ) ?;
2097
2097
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
+ )
2100
2103
. context ( "Falied to write to .origin file" ) ?;
2101
2104
2102
2105
if staged {
2103
2106
std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
2104
2107
. with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
2105
2108
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}" ) ) ?;
2111
2114
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}" ) ) ?;
2113
2121
}
2114
2122
2115
2123
Ok ( ( ) )
0 commit comments