Moved sync outside of filesystem calls

This commit is contained in:
max-amb
2026-06-08 20:46:23 +02:00
committed by Sylvestre Ledru
parent 13d37420bd
commit 4a41104d38
+8 -8
View File
@@ -295,15 +295,8 @@ fn is_best(previous: &[MountInfo], mi: &MountInfo) -> bool {
/// Get all currently mounted filesystems.
///
/// `opt` excludes certain filesystems from consideration and allows for the synchronization of filesystems before running; see
/// [`Options`] for more information.
/// `opt` excludes certain filesystems from consideration; see [`Options`] for more information.
fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
// Run a sync call before any operation if so instructed.
if opt.sync {
#[cfg(not(any(windows, target_os = "redox")))]
rustix::fs::sync();
}
let mut mounts = vec![];
for mut mi in read_fs_list()? {
// TODO The running time of the `is_best()` function is linear
@@ -450,6 +443,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
let opt = Options::from(&matches).map_err(DfError::OptionsError)?;
// Run a sync call before any operation if so instructed.
if opt.sync {
#[cfg(not(any(windows, target_os = "redox")))]
rustix::fs::sync();
}
// Get the list of filesystems to display in the output table.
let filesystems: Vec<Filesystem> = match matches.get_many::<OsString>(OPT_PATHS) {
None => {