notify
notify copied to clipboard
Watch on non-existing file
My scenario is to watch a credential file; if not exist, bypass authentication; otherwise read the content to build the map.
I found that if the file exists and later deleted and recreated, all the loading can happen properly. But notify
requires the file to exist initially:
// https://github.com/thibaudgg/rb-fsevent/blob/master/ext/fsevent_watch/main.c
fn append_path(&mut self, path: &Path, recursive_mode: RecursiveMode) -> Result<()> {
if !path.exists() {
return Err(Error::path_not_found().add_path(path.into()));
}
Since we can anyway delete the file later it starts, I wonder if we can relax this condition (or at lease when RecursiveMode::NonRecursive
) so that make it possible to watch on a maybe non-existing file.
cc @0xpr03
Seems it depends on the OS whether events can be emitted - https://github.com/fsnotify/fsnotify/issues/49
I suggest you watch the parent folder. Does that work for you?
Yes. This is how I finally worked it out - https://github.com/GreptimeTeam/greptimedb/pull/3566/commits/408f8df934313f892b52abfdf55ec3a5ace7e6bb (among https://github.com/GreptimeTeam/greptimedb/pull/3566)