Comments (8)
That's a tough one.
You're right that our implementation is responding to FILE_ACTION_MODIFIED
when "listening" for a bunch of different kinds of events.
One option is to provide a way for the user to configure which "event sources" we care about.
That way, people who don't want access changes to be reported (or, confusingly reported, or reported in a mysterious context) can be better served by the watcher.
What would the API look like? We could pass flags down during the watcher's construction, that's fine and natural, but the flags don't necessarily commute meaning across operating systems.
Maybe we could ifdef out various flags such that, say, watch(patch, cb, watcher::ignore_events_from_file_access or something)
doesn't compile on anything non-windows. I try to avoid different APIs for different platforms, but is this a good exception?
What should the defaults be?
On one hand, this is definitely not an intuitive event.
On the other hand, it's just what the operating system is telling us.
from watcher.
or possibly work around this by caching the timestamp of the load and ignoring modify events near it
FWIW, when I use the watcher to respond to modification events, I usually debounce the events over a second or two.
Various applications will make a bunch of write calls and do some probably unnecessary filesystem ops.
While it's a real issue that the modification event here is either not correct or misleading, debouncing to deal with too-frequent events is also helpful.
I'll look into it. Thanks for using the library.
from watcher.
I'm strongly considering just not reporting "access events" at all.
It would be perfect if we could disambiguate changes from accessing a file from changes to modifying the contents of a file (or directory).
That might be as simple as just spinning up two watchers, one for all events but access, another for the access events. But how do we tell the user about it? Probably a new event type to avoid confusion.
There are ways to get these kinds of access-as-modify events on macOS/ios/linux/inotify/fanotify (and the experimental ebpf watcher). For inotify, I believe the flag IN_ACCESS will do this, and for fanotify, FAN_ATTRIB might give us these events. MacOS watches for them currently.
However, it seems simplest to ignore access-as-modify events on all platforms and wire up a much more complete solution if issues crop up. The utility is questionable.
from watcher.
Thank you for your help
from watcher.
It's particularly bad in my case because I'm trying to use the modify event to know when to reload a file. If the last access time were to continue to get changed, I could be in an infinite loop. I'm not seeing that and I'm not sure why yet. I admit that watcher is really correct here but not sure if more information could be provided so I could ignore these events?
from watcher.
For the short term, I encourage you to hack on this repo and make changes as needed. Either for your particular application or to push changes back.
from watcher.
Thanks for your support @e-dant !
I agree, tricky problem to handle generically through the interface. Outside of platform specific flags, you could maybe add a general thing to ignore "attributes" but that's also somewhat strange. I also wondered about a platform specific pragma to disable this at compile time?
I guess the reason I raised this issue was to question if this behavior made sense for a "modify". For what it's worth, other than atom/watcher from your comparison projects, the other 3 cpp projects do not watch FILE_NOTIFY_CHANGE_LAST_ACCESS
. Not sure how many of them are intentional. There was another issue on this raised here: Axosoft/nsfw#121 . And as called out in that issue, C# also doesn't listen for it by default. Is there anything analogous for the other platforms where it could be its own event?
As for my approach. I see I can simply remove FILE_NOTIFY_CHANGE_LAST_ACCESS
, or possibly work around this by caching the timestamp of the load and ignoring modify events near it. I'll see what I can do.
I'll leave this open for now, let me know if there's any way you'd like to move forward. Thanks again for your help and this library!
from watcher.
However, it seems simplest to ignore access-as-modify events on all platforms and wire up a much more complete solution if issues crop up. The utility is questionable.
I took this comment and decided to run with it :) . I pushed up a PR. Hoping to get my own software released with these changes (and custom forks are a pain in our workflow). If this needs more consideration, feel free to close. Thank you again!
from watcher.
Related Issues (20)
- [api] explore an `asio` interface
- Please provide a way to disable fanotify HOT 3
- Clean Includes
- [api] finalize the api
- Portability thread HOT 1
- compilation error on MSVC since 0.8.1 HOT 3
- is C++17 standard no longer supported? HOT 9
- macOS CI runner occasionally fails due to missing CMake binary HOT 3
- Is `/permissive-` needed on MSVC in 0.9.0? HOT 2
- watcher.hpp includes C++20 standard library <bit> HOT 3
- Windows runner no longer executes executables properly HOT 1
- Which filesystem events correspond to which event::effect_type values? HOT 18
- Handle rename event properly HOT 1
- Compiler error: `chrono:2320:48: note: undefined function '_S_fractional_width' cannot be used in a constant expression` HOT 3
- Watch proc with ebpf HOT 1
- Windows - rename event is split into two events HOT 4
- [macOS] Sometimes the path is not available in a change event. HOT 2
- Python, Node.js, Ruby, Haskell? Language bindings HOT 1
- Consider Rust Bindings HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from watcher.