Skip to content

Commit

Permalink
fix(core): improve error handling for getting metadata during file wa… (
Browse files Browse the repository at this point in the history
#18223)

(cherry picked from commit 4ef66f4)
  • Loading branch information
mandarini authored and FrozenPandaz committed Jul 20, 2023
1 parent 9382ed4 commit 2201eca
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/nx/src/native/watch/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,22 @@ impl From<&Event> for WatchEventInternal {
use std::fs;
use std::os::macos::fs::MetadataExt;

let t = fs::metadata(path_ref).expect("metadata should be available");

let modified_time = t.st_mtime();
let birth_time = t.st_birthtime();

// if a file is created and updated near the same time, we always get a create event
// so we need to check the timestamps to see if it was created or updated
// if the modified time is the same as birth_time then it was created
if modified_time == birth_time {
EventType::create
} else {
EventType::update
let t = fs::metadata(path_ref);
match t {
Err(_) => EventType::delete,
Ok(t) => {
let modified_time = t.st_mtime();
let birth_time = t.st_birthtime();

// if a file is created and updated near the same time, we always get a create event
// so we need to check the timestamps to see if it was created or updated
// if the modified time is the same as birth_time then it was created
if modified_time == birth_time {
EventType::create
} else {
EventType::update
}
}
}
}

Expand Down

0 comments on commit 2201eca

Please sign in to comment.