@@ -9,6 +9,7 @@ use crate::coreos;
99 target_arch = "riscv64"
1010) ) ]
1111use crate :: efi;
12+ use crate :: freezethaw:: fsfreeze_thaw_cycle;
1213use crate :: model:: { ComponentStatus , ComponentUpdatable , ContentMetadata , SavedState , Status } ;
1314use crate :: { ostreeutil, util} ;
1415use anyhow:: { anyhow, Context , Result } ;
@@ -17,7 +18,6 @@ use clap::crate_version;
1718use fn_error_context:: context;
1819use libc:: mode_t;
1920use libc:: { S_IRGRP , S_IROTH , S_IRUSR , S_IWUSR } ;
20- use openat_ext:: OpenatDirExt ;
2121use serde:: { Deserialize , Serialize } ;
2222use std:: borrow:: Cow ;
2323use std:: collections:: BTreeMap ;
@@ -625,21 +625,14 @@ pub(crate) fn client_run_migrate_static_grub_config() -> Result<()> {
625625
626626 strip_grub_config_file ( content, & dirfd, stripped_config) ?;
627627
628- // Sync changes to the filesystem (ignore failures)
629- let _ = dirfd. syncfs ( ) ;
630-
631- // Atomically exchange the configs
628+ // Atomically replace the symlink
632629 dirfd
633- . local_exchange ( stripped_config, "grub.cfg" )
634- . context ( "Failed to exchange symlink with current GRUB config" ) ?;
630+ . local_rename ( stripped_config, "grub.cfg" )
631+ . context ( "Failed to replace symlink with current GRUB config" ) ?;
635632
636- // Sync changes to the filesystem (ignore failures)
637- let _ = dirfd. syncfs ( ) ;
633+ fsfreeze_thaw_cycle ( dirfd. open_file ( "." ) ?) ?;
638634
639635 println ! ( "GRUB config symlink successfully replaced with the current config" ) ;
640-
641- // Remove the now unused symlink (optional cleanup, ignore any failures)
642- _ = dirfd. remove_file ( stripped_config) ;
643636 }
644637 } ;
645638
@@ -690,8 +683,10 @@ fn strip_grub_config_file(
690683 }
691684
692685 writer
693- . flush ( )
694- . context ( "Failed to write stripped GRUB config" ) ?;
686+ . into_inner ( )
687+ . context ( "Failed to flush stripped GRUB config" ) ?
688+ . sync_data ( )
689+ . context ( "Failed to sync stripped GRUB config" ) ?;
695690
696691 Ok ( ( ) )
697692}
0 commit comments