Skip to content

Commit

Permalink
fsevent: return error on canonicalize failure
Browse files Browse the repository at this point in the history
Removes a panic that can occur in `append_path` when a file is removed
after passing the `exists` check, but before canonicalization. This
change moves `canonicalize` before appending the path, so that it can
safely bail on error without leaking state.
  • Loading branch information
jmagnuson authored and 0xpr03 committed Nov 22, 2021
1 parent b3f2d77 commit 07809b9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/fsevent.rs
Expand Up @@ -347,6 +347,7 @@ impl FsEventWatcher {
if !path.exists() {
return Err(Error::path_not_found().add_path(path.into()));
}
let canonical_path = path.to_path_buf().canonicalize()?;
let str_path = path.to_str().unwrap();
unsafe {
let mut err: cf::CFErrorRef = ptr::null_mut();
Expand All @@ -361,7 +362,7 @@ impl FsEventWatcher {
cf::CFRelease(cf_path);
}
self.recursive_info.insert(
path.to_path_buf().canonicalize().unwrap(),
canonical_path,
recursive_mode.is_recursive(),
);
Ok(())
Expand Down

0 comments on commit 07809b9

Please sign in to comment.