From f00b9d62c8bb0632f17608cdc13c95e73be65294 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Fri, 29 Aug 2025 17:34:46 +0800 Subject: [PATCH] runtime-rs: Enhance Copyfile to ensure existing contents synchronized This commit is designed to perform a full sync before starting monitoring to ensure that files which exist before monitoring starts are also synced. Signed-off-by: Alex Lyn --- .../resource/src/volume/share_fs_volume.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/runtime-rs/crates/resource/src/volume/share_fs_volume.rs b/src/runtime-rs/crates/resource/src/volume/share_fs_volume.rs index 0a570a3c74..a4e768ffe6 100644 --- a/src/runtime-rs/crates/resource/src/volume/share_fs_volume.rs +++ b/src/runtime-rs/crates/resource/src/volume/share_fs_volume.rs @@ -160,10 +160,29 @@ impl FsWatcher { let inotify = self.inotify.clone(); let monitor_config = self.config.clone(); + // Perform a full sync before starting monitoring to ensure that files which exist before monitoring starts are also synced. + let agent_sync = agent.clone(); + let src_sync = src.clone(); + let dst_sync = dst.clone(); + tokio::spawn(async move { let mut buffer = [0u8; 4096]; let mut last_event_time = None; + // Initial sync: ensure existing contents in the directory are synchronized + { + info!( + sl!(), + "Initial sync from {:?} to {:?}", &src_sync, &dst_sync + ); + if let Err(e) = + copy_dir_recursively(&src_sync, &dst_sync.display().to_string(), &agent_sync) + .await + { + error!(sl!(), "Initial sync failed: {:?}", e); + } + } + loop { // use cloned inotify instance match inotify.lock().await.read_events(&mut buffer) { @@ -174,7 +193,8 @@ impl FsWatcher { | EventMask::MODIFY | EventMask::DELETE | EventMask::MOVED_FROM - | EventMask::MOVED_TO, + | EventMask::MOVED_TO + | EventMask::CLOSE_WRITE, ) { continue; }