@@ -2063,7 +2063,8 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
2063
2063
}
2064
2064
2065
2065
pub ( crate ) const COMPOSEFS_TRANSIENT_STATE_DIR : & str = "/run/composefs" ;
2066
- pub ( crate ) const COMPOSEFS_STAGED_DEPLOYMENT_PATH : & str = "/run/composefs/staged-deployment" ;
2066
+ /// File created in /run/composefs to record a staged-deployment
2067
+ pub ( crate ) const COMPOSEFS_STAGED_DEPLOYMENT_FNAME : & str = "staged-deployment" ;
2067
2068
/// Relative to /sysroot
2068
2069
pub ( crate ) const STATE_DIR_RELATIVE : & str = "state/deploy" ;
2069
2070
@@ -2105,21 +2106,32 @@ pub(crate) fn write_composefs_state(
2105
2106
. section ( ORIGIN_KEY_BOOT )
2106
2107
. item ( ORIGIN_KEY_BOOT_TYPE , boot_type) ;
2107
2108
2108
- let mut origin_file =
2109
- std:: fs:: File :: create ( state_path. join ( format ! ( "{}.origin" , deployment_id. to_hex( ) ) ) )
2110
- . context ( "Failed to open .origin file" ) ?;
2109
+ let state_dir = cap_std:: fs:: Dir :: open_ambient_dir ( & state_path, cap_std:: ambient_authority ( ) )
2110
+ . context ( "Opening state dir" ) ?;
2111
2111
2112
- origin_file
2113
- . write ( config. to_string ( ) . as_bytes ( ) )
2112
+ state_dir
2113
+ . atomic_write (
2114
+ format ! ( "{}.origin" , deployment_id. to_hex( ) ) ,
2115
+ config. to_string ( ) . as_bytes ( ) ,
2116
+ )
2114
2117
. context ( "Falied to write to .origin file" ) ?;
2115
2118
2116
2119
if staged {
2117
2120
std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
2118
2121
. with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
2119
2122
2120
- let buf = deployment_id. to_hex ( ) ;
2121
- std:: fs:: write ( COMPOSEFS_STAGED_DEPLOYMENT_PATH , buf)
2122
- . with_context ( || format ! ( "Writing {COMPOSEFS_STAGED_DEPLOYMENT_PATH}" ) ) ?;
2123
+ let staged_depl_dir = cap_std:: fs:: Dir :: open_ambient_dir (
2124
+ COMPOSEFS_TRANSIENT_STATE_DIR ,
2125
+ cap_std:: ambient_authority ( ) ,
2126
+ )
2127
+ . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
2128
+
2129
+ staged_depl_dir
2130
+ . atomic_write (
2131
+ COMPOSEFS_STAGED_DEPLOYMENT_FNAME ,
2132
+ deployment_id. to_hex ( ) . as_bytes ( ) ,
2133
+ )
2134
+ . with_context ( || format ! ( "Writing to {COMPOSEFS_STAGED_DEPLOYMENT_FNAME}" ) ) ?;
2123
2135
}
2124
2136
2125
2137
Ok ( ( ) )
0 commit comments