Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Tolerate errors when attempting to fetch metadata for some `CreateKin…
Browse files Browse the repository at this point in the history
…d`s (#3393)

Tolerate errors when attempting to fetch metadata for `CreateKind::Any` or `CreateKind::Other`
  • Loading branch information
DrChat authored Aug 8, 2023
1 parent 8980988 commit 3851ab0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/agent/onefuzz/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -132,17 +132,21 @@ 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));
}

// 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));
match fs::metadata(&path).await {
Ok(metadata) => {
// We're only reporting files, so make sure this is a file first.
if metadata.is_file() {
return Ok(Some(path));
}
}
Err(e) => {
warn!("failed to get metadata for {}: {:?}", path.display(), e);
}
}
}
}
Expand Down

0 comments on commit 3851ab0

Please sign in to comment.