Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InotifyObserver deals poorly with moves from/to outside the watched directory #1094

Open
ericloewe opened this issue Jan 20, 2025 · 2 comments

Comments

@ericloewe
Copy link

My use case is as follows: I want to watch a directory, which is a dropbox into which directories full of files and subdirs are atomically moved (FTP use case) - I want to be notified of these directories having been moved into the watched directory, so that I can process them.

The problem is that without hacking around the top-level API, the move events are converted from MOVED_TO to CREATED (similarly, MOVED_FROM gets turned into DELETED). Inotify itself reports these as expected, as seen from the debug logs, but then this bizarre conversion happens in InotifyEmitter.queue_events, from around line 156.
Specifically, this happens when events cross the watched boundary - in other words, moves within the watched directory are reported correctly, but moves to/from outside the watched directory get mangled.

This behavior is conditional on the full_events flag, but there is no documented way of setting this flag. From what I can see, the only solution is to manually bypass the Observer() helper function by reimplementing its functionality, e.g.:

def get_observer() -> watchdog.observers.api.BaseObserver:
    """Work around Watchdog's top-level API"""
    if platform.is_linux():
        with contextlib.suppress(UnsupportedLibcError):
            from watchdog.observers.inotify import InotifyObserver

            return InotifyObserver(generate_full_events=True)

So I have two questions:

  1. Is there a reasoning behind this behavior? I understand that some use cases are fine with it, but it would seem beneficial to not abstract away the distinction between a move and a create/delete.
  2. Is there a reasoning for this not to be exposed in the API or docs?
@BoboTiG
Copy link
Collaborator

BoboTiG commented Jan 20, 2025

Both questions are valid, and I do not have answers right now. I'll dig into the history.

I think we could enhance the exposed API in any cases to allow setting the generate_full_events without having to deal with such low-level code.

@ericloewe
Copy link
Author

My quick and dirty analysis is that not all Observers support these semantics. Kqueue doesn't deal with the move destination, as I understand it, so this is a complete non-starter. Polling also would seem to not allow these events to be detected. The Windows API does seem to report moves across the watch boundary, but I haven't followed the code nor tested it myself - but it doesn't seem to be propagating them to the higher levels of the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants