-
Notifications
You must be signed in to change notification settings - Fork 111
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
Allow entr
to watch directories (fixes #470)
#500
Conversation
With this new version, tests should pass for Here are some points mentioned in #492, on which I'm following up here since this is the most up-to-date PR.
I tried to explicitly test for the specific case where watched directories are empty, but eventually realized that this was probably not what you talked about. This prompted me to investigate how things currently work, in a more detailed way. The reason the current implementation works for directories is because watching a directory (say:
The "empty filename" entry corresponds to watching the directory itself (as opposed to watching a file in it). That "empty filename" entry is examined each time the directory is modified. And So there is an explanation why things actually currently work here. But it could probably be argued that this whole mechanism is a bit brittle: relying on the file-deletion notification process to trigger directory notifications is probably not a very good idea. And a negative side-effect which already affects us is that an additional 0.1s delay is introduced in the loop, which is unnecessary in this case. I think the correct way to handle things here would be to unconditionally push the
No worries! I have not been particularly responsive either... I could (and probably should) have made this PR last week!
Yes, this is what I used to test my implementation on my Linux system. The reason why I am (probably needlessly) concerned about BSD systems is the following:
That being said, the current implementation seems to pass all tests in both modes. Maybe a pragmatic way of doing things would be to ship this as it is, assume that things work everywhere, and wait to see whether BSD users complain. |
That sounds great to me! Thanks for digging into the mechanism here. |
bcb31d3
to
3185257
Compare
You're very welcome! I just added it (in the same commit: I didn't feel like such a small change deserved its own commit) Please don't hesitate to let me know what you think (but there is no rush!) |
src/pkgs.jl
Outdated
@@ -381,7 +381,11 @@ function watch_files_via_dir(dirname) | |||
wf = watched_files[dirname] | |||
for (file, id) in wf.trackedfiles | |||
fullpath = joinpath(dirname, file) | |||
if !file_exists(fullpath) | |||
if isdir(fullpath) | |||
println("detected dir modification: $fullpath") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks great, but what's the motivation for the notification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry! I used this in my early tests and forgot to remove the line. I replaced it with a comment in the commit I just pushed.
Thanks for the thorough review!
This fixes uses of `entr` to watch directories, both when `Revise` watches directories (`watching_files[] = false`) and when it watches files (`watching_files[] = true`). Tests mirror those defined for `entr` on regular files, and check in particular that: - file creations, modifications and deletions in the directory are correctly detected; - clustered notifications trigger the callback only once; - empty directories are correctly handled (i.e. they remain in the watch list even when all files in them are deleted). Closes: timholy#470
Thank you so much for a wonderful contribution! |
This PR extends the work done in #492 to allow
entr
to watch directories. It is also re-based on the currentmaster
, in order to benefit from the latest bug fixes inentr
.At this stage, everything works in the case where
Revise.watching_files[] == false
. The tests performed forentr
on directories mirror those defined forentr
on files. In particular, they check that:Upcoming commits should complete this PR to handle the case where
Revise.watching_files[]
is set.