backend_fen.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //go:build solaris
  2. // +build solaris
  3. package fsnotify
  4. import (
  5. "errors"
  6. )
  7. // Watcher watches a set of paths, delivering events on a channel.
  8. //
  9. // A watcher should not be copied (e.g. pass it by pointer, rather than by
  10. // value).
  11. //
  12. // # Linux notes
  13. //
  14. // When a file is removed a Remove event won't be emitted until all file
  15. // descriptors are closed, and deletes will always emit a Chmod. For example:
  16. //
  17. // fp := os.Open("file")
  18. // os.Remove("file") // Triggers Chmod
  19. // fp.Close() // Triggers Remove
  20. //
  21. // This is the event that inotify sends, so not much can be changed about this.
  22. //
  23. // The fs.inotify.max_user_watches sysctl variable specifies the upper limit
  24. // for the number of watches per user, and fs.inotify.max_user_instances
  25. // specifies the maximum number of inotify instances per user. Every Watcher you
  26. // create is an "instance", and every path you add is a "watch".
  27. //
  28. // These are also exposed in /proc as /proc/sys/fs/inotify/max_user_watches and
  29. // /proc/sys/fs/inotify/max_user_instances
  30. //
  31. // To increase them you can use sysctl or write the value to the /proc file:
  32. //
  33. // # Default values on Linux 5.18
  34. // sysctl fs.inotify.max_user_watches=124983
  35. // sysctl fs.inotify.max_user_instances=128
  36. //
  37. // To make the changes persist on reboot edit /etc/sysctl.conf or
  38. // /usr/lib/sysctl.d/50-default.conf (details differ per Linux distro; check
  39. // your distro's documentation):
  40. //
  41. // fs.inotify.max_user_watches=124983
  42. // fs.inotify.max_user_instances=128
  43. //
  44. // Reaching the limit will result in a "no space left on device" or "too many open
  45. // files" error.
  46. //
  47. // # kqueue notes (macOS, BSD)
  48. //
  49. // kqueue requires opening a file descriptor for every file that's being watched;
  50. // so if you're watching a directory with five files then that's six file
  51. // descriptors. You will run in to your system's "max open files" limit faster on
  52. // these platforms.
  53. //
  54. // The sysctl variables kern.maxfiles and kern.maxfilesperproc can be used to
  55. // control the maximum number of open files, as well as /etc/login.conf on BSD
  56. // systems.
  57. //
  58. // # macOS notes
  59. //
  60. // Spotlight indexing on macOS can result in multiple events (see [#15]). A
  61. // temporary workaround is to add your folder(s) to the "Spotlight Privacy
  62. // Settings" until we have a native FSEvents implementation (see [#11]).
  63. //
  64. // [#11]: https://github.com/fsnotify/fsnotify/issues/11
  65. // [#15]: https://github.com/fsnotify/fsnotify/issues/15
  66. type Watcher struct {
  67. // Events sends the filesystem change events.
  68. //
  69. // fsnotify can send the following events; a "path" here can refer to a
  70. // file, directory, symbolic link, or special file like a FIFO.
  71. //
  72. // fsnotify.Create A new path was created; this may be followed by one
  73. // or more Write events if data also gets written to a
  74. // file.
  75. //
  76. // fsnotify.Remove A path was removed.
  77. //
  78. // fsnotify.Rename A path was renamed. A rename is always sent with the
  79. // old path as Event.Name, and a Create event will be
  80. // sent with the new name. Renames are only sent for
  81. // paths that are currently watched; e.g. moving an
  82. // unmonitored file into a monitored directory will
  83. // show up as just a Create. Similarly, renaming a file
  84. // to outside a monitored directory will show up as
  85. // only a Rename.
  86. //
  87. // fsnotify.Write A file or named pipe was written to. A Truncate will
  88. // also trigger a Write. A single "write action"
  89. // initiated by the user may show up as one or multiple
  90. // writes, depending on when the system syncs things to
  91. // disk. For example when compiling a large Go program
  92. // you may get hundreds of Write events, so you
  93. // probably want to wait until you've stopped receiving
  94. // them (see the dedup example in cmd/fsnotify).
  95. //
  96. // fsnotify.Chmod Attributes were changed. On Linux this is also sent
  97. // when a file is removed (or more accurately, when a
  98. // link to an inode is removed). On kqueue it's sent
  99. // and on kqueue when a file is truncated. On Windows
  100. // it's never sent.
  101. Events chan Event
  102. // Errors sends any errors.
  103. Errors chan error
  104. }
  105. // NewWatcher creates a new Watcher.
  106. func NewWatcher() (*Watcher, error) {
  107. return nil, errors.New("FEN based watcher not yet supported for fsnotify\n")
  108. }
  109. // Close removes all watches and closes the events channel.
  110. func (w *Watcher) Close() error {
  111. return nil
  112. }
  113. // Add starts monitoring the path for changes.
  114. //
  115. // A path can only be watched once; attempting to watch it more than once will
  116. // return an error. Paths that do not yet exist on the filesystem cannot be
  117. // added. A watch will be automatically removed if the path is deleted.
  118. //
  119. // A path will remain watched if it gets renamed to somewhere else on the same
  120. // filesystem, but the monitor will get removed if the path gets deleted and
  121. // re-created, or if it's moved to a different filesystem.
  122. //
  123. // Notifications on network filesystems (NFS, SMB, FUSE, etc.) or special
  124. // filesystems (/proc, /sys, etc.) generally don't work.
  125. //
  126. // # Watching directories
  127. //
  128. // All files in a directory are monitored, including new files that are created
  129. // after the watcher is started. Subdirectories are not watched (i.e. it's
  130. // non-recursive).
  131. //
  132. // # Watching files
  133. //
  134. // Watching individual files (rather than directories) is generally not
  135. // recommended as many tools update files atomically. Instead of "just" writing
  136. // to the file a temporary file will be written to first, and if successful the
  137. // temporary file is moved to to destination removing the original, or some
  138. // variant thereof. The watcher on the original file is now lost, as it no
  139. // longer exists.
  140. //
  141. // Instead, watch the parent directory and use Event.Name to filter out files
  142. // you're not interested in. There is an example of this in [cmd/fsnotify/file.go].
  143. func (w *Watcher) Add(name string) error {
  144. return nil
  145. }
  146. // Remove stops monitoring the path for changes.
  147. //
  148. // Directories are always removed non-recursively. For example, if you added
  149. // /tmp/dir and /tmp/dir/subdir then you will need to remove both.
  150. //
  151. // Removing a path that has not yet been added returns [ErrNonExistentWatch].
  152. func (w *Watcher) Remove(name string) error {
  153. return nil
  154. }