From 2201ecace684f7b3588d351cee040380eb741c32 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 20 Jul 2023 19:34:58 +0300 Subject: [PATCH] =?UTF-8?q?fix(core):=20improve=20error=20handling=20for?= =?UTF-8?q?=20getting=20metadata=20during=20file=20wa=E2=80=A6=20(#18223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 4ef66f4afd01e5aec4f813eae16fd7fa438230f4) --- packages/nx/src/native/watch/types.rs | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/nx/src/native/watch/types.rs b/packages/nx/src/native/watch/types.rs index 21fe0f94dacd8..88fa2b0f2df4e 100644 --- a/packages/nx/src/native/watch/types.rs +++ b/packages/nx/src/native/watch/types.rs @@ -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 + } + } } }