Comments (4)
I looked around a bit, and:
-
Linux has OPEN and CLOSE events, FreeBSD has NOTE_OPEN, NOTE_CLOSE, NOTE_CLOSE_WRITE, but none of the other kqueue platforms do; Windows and FEN doesn't have it either.
-
Unmount is available on inotify and FEN, but none of the kqueue platforms or Windows.
-
Read is on FreeBSD, Linux (as ACCESS), FEN (as ACCESS), Windows (LAST_ACCESS), but none of the other kqueue platforms.
As far as I can see, there are no events that are shared by all platforms.
Need to think about how to best deal with this; #67 would be okay for some rare operations, but things like Read is available on quite a few platforms, and using a new .Sys() would be awkward.
One way might be creating a new UnportableOp type:
// UnportableOp are file operations that are not available on all platforms.
type UnportableOp uint32
const (
Read OP = 1 << iota
Open
Close
// ...
)
type Event struct {
Name string
Op Op
Unportable UnportableOp
}
func (e Event) HasUnportable(op UnportableOp) bool {
return e.Unportable.Has(op)
}
This way it's always clear you're using unportable operations and can't accidentally do e.Has(fsnotify.Read)
and expecting it to work on all platforms; I don't trust people to read the documentation because experience has proven many don't (plus, it's easy to forget). On the other hand, having two types is a bit of a pain.
from fsnotify.
@arp242 What about leveraging GOOS build tags to limit which events can be used?
You could have a file or package for windows specific events, one for inotify specific events, etc
If each platform's non-portable bits had their own package, their usage limitations would be self documenting (eg inotify.Close
, defined in github.com/fsnotify/fsnotify/pkg/inotify)
Would there be a problem with making this seamlessly handled by go build, without any kind of explicit opt-in?
With non-portable events guarded by build flags, if someone tried to build the following code for darwin, they'd get a compilation error:
event := <-watcher.Events
if event.Has(inotify.Close) {
fmt.Println("File was closed")
}
from fsnotify.
The problem with that is that many unportable events are supported by more than one platform. And even for events on one platform it's awkward to have fallbacks – I suppose you could make special handling for every platform, but that somewhat defeats the purpose of this library.
Anyway, proposal at: #629
from fsnotify.
Overview of additional event types:
inotify
IN_ACCESS File was accessed (e.g., read(2), execve(2)).
IN_CLOSE_NOWRITE File or directory not opened for writing was closed.
IN_CLOSE_WRITE File opened for writing was closed.
IN_OPEN File or directory was opened.
fanotify
FAN_ACCESS file or a directory (but see BUGS) was accessed (read).
FAN_CLOSE_NOWRITE file or directory that was opened read-only (O_RDONLY) was closed.
FAN_CLOSE_WRITE file that was opened for writing (O_WRONLY or O_RDWR) was closed.
FAN_FS_ERROR filesystem error was detected.
FAN_OPEN file or a directory was opened.
FAN_OPEN_EXEC file was opened with the intent to be executed.
FreeBSD
NOTE_CLOSE A file descriptor referencing the monitored file, was closed. The closed file de scriptor did not have write access.
NOTE_CLOSE_WRITE A file descriptor referencing the monitored file, was closed. The closed file descriptor had write access.
NOTE_EXTEND For regular file, the file referenced by the descriptor was extended.
NOTE_LINK The link count on the file changed.
NOTE_OPEN The file referenced by the descriptor was opened.
NOTE_READ A read occurred on the file referenced by the descriptor.
NOTE_REVOKE Access to the file was revoked via revoke(2) or the underlying file system was unmounted.
OpenBSD
NOTE_EXTEND The file referenced by the descriptor was extended.
NOTE_LINK The link count on the file changed.
NOTE_TRUNCATE The file referenced by the descriptor was truncated.
NetBSD
NOTE_EXTEND The file referenced by the descriptor was extended.
NOTE_LINK The link count on the file changed.
NOTE_REVOKE Access to the file was revoked via revoke(2) or the underlying file system was unmounted.
Added in NetBSD 10 (March 2024, needs update to x/sys)
NOTE_CLOSE A file descriptor without write access referencing the file was closed.
NOTE_CLOSE_WRITE A file descriptor with write access referencing the file was closed.
NOTE_OPEN The file referenced by the descriptor was opened.
NOTE_READ A read occurred on the file referenced by the descriptor.
DragonflyBSD
NOTE_EXTEND The file referenced by the descriptor was extended.
NOTE_LINK The link count on the file changed.
NOTE_REVOKE Access to the file was revoked via revoke(2) or the underlying fileystem was unmounted.
FEN
FILE_ACCESS fo_atime change
FILE_TRUNC op that induced the time stamp update also truncated the file
MOUNTEDOVER /* Monitored file/directory was mounted over */
UNMOUNTED /* Monitored file system got unmounted */
Windows
CHANGE_LAST_ACCESS Any change to the last access time
CHANGE_SIZE Any file-size change in the watched directory or subtree (might reasonably emulate CloseWrite?)
fsevents
?
from fsnotify.
Related Issues (20)
- When remove a watching directory not triggered remove event HOT 5
- How to get the process info that modified the file HOT 3
- fsnotify: queue or buffer overflow HOT 1
- In Docker container. fsnotify package error: "fsnotify: queue or buffer overflow. " HOT 5
- Add dependabot to update your GitHub Actions HOT 1
- The reason why queue or buffer overflow? HOT 1
- Support for intermediary multiplexer like watchman HOT 5
- Infinite WRITE events when watching $TMPDIR on MacOS HOT 3
- Write Events Fired Multiple Times for File Changes HOT 1
- Can we add a polling interval to the watcher to scan the mentioned directory after a particular time interval and not continuously? HOT 6
- Proposed approach for a different type of fanotify backend HOT 10
- Inconsistent behavior of WatchList on Windows and Unix HOT 5
- Received an unexpected is to see HOT 2
- There is a directory with some files in it, watch this directory and how to return the files that already exist. HOT 1
- panic in v1.7.0 HOT 8
- illumos: track renames HOT 1
- documentation: double `to to` in Add method of fsnotify.Watcher HOT 3
- support of CLOSE_WRITE event does not work HOT 11
- When removing symlink no events happens on MacOS. HOT 1
- When adding invalid directory to watch list it is return error but also adding to list too.
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 fsnotify.