watchdog icon indicating copy to clipboard operation
watchdog copied to clipboard

[Question] How to follow symbolic link

Open fenghse opened this issue 9 years ago • 8 comments

I found that it does not follow the symbolic link, how to make it follow sym-link?

fenghse avatar Jul 22 '16 09:07 fenghse

My guess is this occurs because the a symbolic link is considered a file, even if it points to a directory. You could solve this by iterating through your watched folders and adding new watches to each symbolic link pointing to a directory. If there's demand for this, I might be able to add an option to make symbolic links pointing to directories enabled through an optional parameter.

DonyorM avatar Aug 24 '16 11:08 DonyorM

A simple solution is to apply os.path.realpath on all watched folders. So, we end up with something like:

observer.schedule(event_handler, os.path.realpath(path))

It could be by default in the library. Eventually with a verification that the simlink, if it is one, is not broken.

Aluriak avatar Sep 10 '16 00:09 Aluriak

You do not specify platform. I implemented a fix for Linux on my branch... see if it helps: https://github.com/petersilva/watchdog

petersilva avatar Jan 22 '17 20:01 petersilva

A regular directory I have here contains several symbolic links, each of which points to a file that lives elsewhere. When the content of any such file changes, I want to be alerted. That does not happen out of the box and I do not see how to make it happen via watchdog.

I'm under Linux. In a somewhat desperate attempt, I removed a symbolic link and replace it with a single-file-mount, something like touch file && sudo mount --bind ../otherdir/file file, as a workaround. But even that did not work.

aknrdureegaesr avatar Feb 05 '24 13:02 aknrdureegaesr

I found that this works for my case:

from watchdog.observers.polling import PollingObserver as Observer

Not much later: A brief test suggests that this also works in the "symlink to directory" case.

aknrdureegaesr avatar Feb 05 '24 13:02 aknrdureegaesr