From 35d0a1eb5c3a28e60f2efe0a2ed259f1f58945b8 Mon Sep 17 00:00:00 2001 From: hlsxx Date: Mon, 27 Apr 2026 15:38:51 +0200 Subject: [PATCH] refactor(sync): DRY do_sync_with function --- src/uu/sync/src/sync.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index b34d0ac0b..07f47fc4f 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -80,25 +80,27 @@ mod platform { } #[cfg(any(target_os = "linux", target_os = "android"))] - pub fn do_syncfs(files: Vec) -> UResult<()> { + pub fn do_sync_with(files: Vec, op: F) -> UResult<()> + where + F: Fn(File) -> Result<(), nix::Error>, + { for path in files { let f = open_and_reset_nonblock(&path)?; - syncfs(f).map_err_context( + op(f).map_err_context( || translate!("sync-error-syncing-file", "file" => path.quote()), )?; } Ok(()) } + #[cfg(any(target_os = "linux", target_os = "android"))] + pub fn do_syncfs(files: Vec) -> UResult<()> { + do_sync_with(files, syncfs) + } + #[cfg(any(target_os = "linux", target_os = "android"))] pub fn do_fdatasync(files: Vec) -> UResult<()> { - for path in files { - let f = open_and_reset_nonblock(&path)?; - fdatasync(f).map_err_context( - || translate!("sync-error-syncing-file", "file" => path.quote()), - )?; - } - Ok(()) + do_sync_with(files, fdatasync) } }