From 2e44020b2b613b46c6c461ed35ac9162047e013b Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 09:45:02 -0500 Subject: [PATCH 1/7] Tolerate errors when attempting to fetch metadata for `CreateKind::Any` or `CreateKind::Other` --- src/agent/onefuzz/src/monitor.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index 5715b8bdf7..d95902cca7 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; -use anyhow::{format_err, Context, Result}; +use anyhow::{format_err, Result}; use notify::{ event::{CreateKind, ModifyKind, RenameMode}, Event, EventKind, Watcher, @@ -136,13 +136,11 @@ impl DirectoryMonitor { return Ok(Some(path)); } - // check if it is a file - let metadata = fs::metadata(&path) - .await - .context("checking metadata for file")?; - - if metadata.is_file() { - return Ok(Some(path)); + if let Ok(metadata) = fs::metadata(&path).await { + // check if it is a file + if metadata.is_file() { + return Ok(Some(path)); + } } } } From 8a0e980ceddd31360d6bcd8b7be39818e5509074 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 11:14:32 -0500 Subject: [PATCH 2/7] Don't report directory if metadata lookup fails --- src/agent/onefuzz/src/monitor.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index d95902cca7..83b5913df7 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -132,13 +132,9 @@ impl DirectoryMonitor { } } CreateKind::Any | CreateKind::Other => { - if self.report_directories { - return Ok(Some(path)); - } - if let Ok(metadata) = fs::metadata(&path).await { - // check if it is a file - if metadata.is_file() { + // check if it is a file or a folder + if metadata.is_file() || self.report_directories { return Ok(Some(path)); } } From 64e50b619c82fc8a0f090278c664aeff24a7f252 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 12:43:21 -0500 Subject: [PATCH 3/7] Log error as a warning --- src/agent/onefuzz/src/monitor.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index 83b5913df7..9b4f204453 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; -use anyhow::{format_err, Result}; +use anyhow::{format_err, Context, Result}; use notify::{ event::{CreateKind, ModifyKind, RenameMode}, Event, EventKind, Watcher, @@ -132,10 +132,21 @@ impl DirectoryMonitor { } } CreateKind::Any | CreateKind::Other => { - if let Ok(metadata) = fs::metadata(&path).await { - // check if it is a file or a folder - if metadata.is_file() || self.report_directories { - return Ok(Some(path)); + match fs::metadata(&path).await { + Ok(metadata) => { + // check if it is a file or a folder + if metadata.is_file() || self.report_directories { + return Ok(Some(path)); + } + } + Err(e) => { + warn!( + "{}", + Err(e).context(format!( + "failed to get metadata for {}", + path.display() + )) + ); } } } From 54f97a7d20c2eadbcd1a65fa2e68aa3a4606d39a Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 12:47:23 -0500 Subject: [PATCH 4/7] plz work --- src/agent/onefuzz/src/monitor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index 9b4f204453..7c9b4dd379 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -141,7 +141,7 @@ impl DirectoryMonitor { } Err(e) => { warn!( - "{}", + "{:?}", Err(e).context(format!( "failed to get metadata for {}", path.display() From 94b87bf565cd430b236c7999deda8efa92cf3b84 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 13:01:35 -0500 Subject: [PATCH 5/7] now it works --- src/agent/onefuzz/src/monitor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index 7c9b4dd379..1ecf869c2a 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -142,7 +142,7 @@ impl DirectoryMonitor { Err(e) => { warn!( "{:?}", - Err(e).context(format!( + Err::<(), _>(e).context(format!( "failed to get metadata for {}", path.display() )) From 48a61e6b01eefa35cdf0b2b1412fafeb13798b3f Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 13:04:04 -0500 Subject: [PATCH 6/7] prettify --- src/agent/onefuzz/src/monitor.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index 1ecf869c2a..25dc1441d7 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; -use anyhow::{format_err, Context, Result}; +use anyhow::{format_err, Result}; use notify::{ event::{CreateKind, ModifyKind, RenameMode}, Event, EventKind, Watcher, @@ -140,13 +140,7 @@ impl DirectoryMonitor { } } Err(e) => { - warn!( - "{:?}", - Err::<(), _>(e).context(format!( - "failed to get metadata for {}", - path.display() - )) - ); + warn!("failed to get metadata for {}: {:?}", path.display(), e); } } } From acebd021487d057f2560b14aec36622ac5e17329 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Tue, 8 Aug 2023 15:35:26 -0500 Subject: [PATCH 7/7] add back short-circuit --- src/agent/onefuzz/src/monitor.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/agent/onefuzz/src/monitor.rs b/src/agent/onefuzz/src/monitor.rs index 25dc1441d7..32938a46ec 100644 --- a/src/agent/onefuzz/src/monitor.rs +++ b/src/agent/onefuzz/src/monitor.rs @@ -132,10 +132,15 @@ impl DirectoryMonitor { } } CreateKind::Any | CreateKind::Other => { + // Short-circuit and report this path if we're reporting everything. + if self.report_directories { + return Ok(Some(path)); + } + match fs::metadata(&path).await { Ok(metadata) => { - // check if it is a file or a folder - if metadata.is_file() || self.report_directories { + // We're only reporting files, so make sure this is a file first. + if metadata.is_file() { return Ok(Some(path)); } }