Skip to content

Commit cf2f71f

Browse files
committed
Reduce fs::metadata call on Windows
1 parent 252b4da commit cf2f71f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

notify/src/windows.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,21 @@ impl ReadDirectoryChangesServer {
165165
}
166166

167167
fn add_watch(&mut self, path: PathBuf, is_recursive: bool) -> Result<PathBuf> {
168+
let metadata = path.metadata();
168169
// path must exist and be either a file or directory
169-
if !path.is_dir() && !path.is_file() {
170+
if metadata
171+
.as_ref()
172+
.map(|m| !m.is_dir() && !m.is_file())
173+
.unwrap_or(true)
174+
{
170175
return Err(
171176
Error::generic("Input watch path is neither a file nor a directory.")
172177
.add_path(path),
173178
);
174179
}
175180

176181
let (watching_file, dir_target) = {
177-
if path.is_dir() {
182+
if metadata.map(|m| m.is_dir()).unwrap_or(false) {
178183
(false, path.clone())
179184
} else {
180185
// emulate file watching by watching the parent directory
@@ -534,12 +539,6 @@ impl ReadDirectoryChangesWatcher {
534539
let p = env::current_dir().map_err(Error::io)?;
535540
p.join(path)
536541
};
537-
// path must exist and be either a file or directory
538-
if !pb.is_dir() && !pb.is_file() {
539-
return Err(Error::generic(
540-
"Input watch path is neither a file nor a directory.",
541-
));
542-
}
543542
self.send_action_require_ack(Action::Watch(pb.clone(), recursive_mode), &pb)
544543
}
545544

0 commit comments

Comments
 (0)