diff --git a/main.py b/main.py index b4eb646..e1bf87e 100644 --- a/main.py +++ b/main.py @@ -59,12 +59,19 @@ def main(): if events: for event in events: logging.debug(f"Event: {event!r}") + if event.mask & flags.IGNORED: + logging.info(f"Watch for wd {event.wd} was removed (directory deleted?).") + if event.wd in wd_to_path: + logging.info(f"Removing path '{wd_to_path[event.wd]}' from watch mapping.") + del wd_to_path[event.wd] + continue + if event.mask & flags.ISDIR and (event.mask & flags.CREATE or event.mask & flags.MOVED_TO): parent_dir_path = wd_to_path.get(event.wd) if not parent_dir_path: logging.warning(f"Could not find path for watch descriptor {event.wd}") continue - new_dir_path = os.path.join(parent_dir_path, event.name.decode('utf-8')) + new_dir_path = os.path.join(parent_dir_path, event.name) logging.info(f"New directory {new_dir_path} detected, adding watches.") add_watch_recursive(inotify, new_dir_path, watch_flags, wd_to_path) continue