Skip to content

Commit 2f64ffe

Browse files
committed
migrate_static_grub_config: use fsfreeze_thaw_cycle()
1 parent 01501b2 commit 2f64ffe

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/bootupd.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::coreos;
99
target_arch = "riscv64"
1010
))]
1111
use crate::efi;
12+
use crate::freezethaw::fsfreeze_thaw_cycle;
1213
use crate::model::{ComponentStatus, ComponentUpdatable, ContentMetadata, SavedState, Status};
1314
use crate::{ostreeutil, util};
1415
use anyhow::{anyhow, Context, Result};
@@ -17,7 +18,6 @@ use clap::crate_version;
1718
use fn_error_context::context;
1819
use libc::mode_t;
1920
use libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWUSR};
20-
use openat_ext::OpenatDirExt;
2121
use serde::{Deserialize, Serialize};
2222
use std::borrow::Cow;
2323
use 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

Comments
 (0)