mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-25 14:23:11 +00:00
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 <alex.lyn@antgroup.com>
This commit is contained in:
@@ -159,10 +159,28 @@ impl FsWatcher {
|
|||||||
let inotify = self.inotify.clone();
|
let inotify = self.inotify.clone();
|
||||||
let monitor_config = self.config.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 {
|
tokio::spawn(async move {
|
||||||
let mut buffer = [0u8; 4096];
|
let mut buffer = [0u8; 4096];
|
||||||
let mut last_event_time = None;
|
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.to_string_lossy(), &agent_sync).await
|
||||||
|
{
|
||||||
|
error!(sl!(), "Initial sync failed: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// use cloned inotify instance
|
// use cloned inotify instance
|
||||||
match inotify.lock().await.read_events(&mut buffer) {
|
match inotify.lock().await.read_events(&mut buffer) {
|
||||||
@@ -173,7 +191,8 @@ impl FsWatcher {
|
|||||||
| EventMask::MODIFY
|
| EventMask::MODIFY
|
||||||
| EventMask::DELETE
|
| EventMask::DELETE
|
||||||
| EventMask::MOVED_FROM
|
| EventMask::MOVED_FROM
|
||||||
| EventMask::MOVED_TO,
|
| EventMask::MOVED_TO
|
||||||
|
| EventMask::CLOSE_WRITE,
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -225,7 +244,7 @@ impl FsWatcher {
|
|||||||
if Instant::now().duration_since(t) > DEBOUNCE_TIME && *need_sync.lock().await {
|
if Instant::now().duration_since(t) > DEBOUNCE_TIME && *need_sync.lock().await {
|
||||||
info!(sl!(), "debounce handle copyfile {:?} -> {:?}", &src, &dst);
|
info!(sl!(), "debounce handle copyfile {:?} -> {:?}", &src, &dst);
|
||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
copy_dir_recursively(&src, &dst.display().to_string(), &agent).await
|
copy_dir_recursively(&src, &dst.to_string_lossy(), &agent).await
|
||||||
{
|
{
|
||||||
error!(
|
error!(
|
||||||
sl!(),
|
sl!(),
|
||||||
|
|||||||
Reference in New Issue
Block a user