backend_other.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //go:build appengine || (!darwin && !dragonfly && !freebsd && !openbsd && !linux && !netbsd && !solaris && !windows)
  2. // +build appengine !darwin,!dragonfly,!freebsd,!openbsd,!linux,!netbsd,!solaris,!windows
  3. // Note: the documentation on the Watcher type and methods is generated from
  4. // mkdoc.zsh
  5. package fsnotify
  6. import "errors"
  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. // # Windows notes
  59. //
  60. // Paths can be added as "C:\path\to\dir", but forward slashes
  61. // ("C:/path/to/dir") will also work.
  62. //
  63. // When a watched directory is removed it will always send an event for the
  64. // directory itself, but may not send events for all files in that directory.
  65. // Sometimes it will send events for all times, sometimes it will send no
  66. // events, and often only for some files.
  67. //
  68. // The default ReadDirectoryChangesW() buffer size is 64K, which is the largest
  69. // value that is guaranteed to work with SMB filesystems. If you have many
  70. // events in quick succession this may not be enough, and you will have to use
  71. // [WithBufferSize] to increase the value.
  72. type Watcher struct {
  73. // Events sends the filesystem change events.
  74. //
  75. // fsnotify can send the following events; a "path" here can refer to a
  76. // file, directory, symbolic link, or special file like a FIFO.
  77. //
  78. // fsnotify.Create A new path was created; this may be followed by one
  79. // or more Write events if data also gets written to a
  80. // file.
  81. //
  82. // fsnotify.Remove A path was removed.
  83. //
  84. // fsnotify.Rename A path was renamed. A rename is always sent with the
  85. // old path as Event.Name, and a Create event will be
  86. // sent with the new name. Renames are only sent for
  87. // paths that are currently watched; e.g. moving an
  88. // unmonitored file into a monitored directory will
  89. // show up as just a Create. Similarly, renaming a file
  90. // to outside a monitored directory will show up as
  91. // only a Rename.
  92. //
  93. // fsnotify.Write A file or named pipe was written to. A Truncate will
  94. // also trigger a Write. A single "write action"
  95. // initiated by the user may show up as one or multiple
  96. // writes, depending on when the system syncs things to
  97. // disk. For example when compiling a large Go program
  98. // you may get hundreds of Write events, and you may
  99. // want to wait until you've stopped receiving them
  100. // (see the dedup example in cmd/fsnotify).
  101. //
  102. // Some systems may send Write event for directories
  103. // when the directory content changes.
  104. //
  105. // fsnotify.Chmod Attributes were changed. On Linux this is also sent
  106. // when a file is removed (or more accurately, when a
  107. // link to an inode is removed). On kqueue it's sent
  108. // when a file is truncated. On Windows it's never
  109. // sent.
  110. Events chan Event
  111. // Errors sends any errors.
  112. //
  113. // ErrEventOverflow is used to indicate there are too many events:
  114. //
  115. // - inotify: There are too many queued events (fs.inotify.max_queued_events sysctl)
  116. // - windows: The buffer size is too small; WithBufferSize() can be used to increase it.
  117. // - kqueue, fen: Not used.
  118. Errors chan error
  119. }
  120. // NewWatcher creates a new Watcher.
  121. func NewWatcher() (*Watcher, error) {
  122. return nil, errors.New("fsnotify not supported on the current platform")
  123. }
  124. // NewBufferedWatcher creates a new Watcher with a buffered Watcher.Events
  125. // channel.
  126. //
  127. // The main use case for this is situations with a very large number of events
  128. // where the kernel buffer size can't be increased (e.g. due to lack of
  129. // permissions). An unbuffered Watcher will perform better for almost all use
  130. // cases, and whenever possible you will be better off increasing the kernel
  131. // buffers instead of adding a large userspace buffer.
  132. func NewBufferedWatcher(sz uint) (*Watcher, error) { return NewWatcher() }
  133. // Close removes all watches and closes the Events channel.
  134. func (w *Watcher) Close() error { return nil }
  135. // WatchList returns all paths explicitly added with [Watcher.Add] (and are not
  136. // yet removed).
  137. //
  138. // Returns nil if [Watcher.Close] was called.
  139. func (w *Watcher) WatchList() []string { return nil }
  140. // Add starts monitoring the path for changes.
  141. //
  142. // A path can only be watched once; watching it more than once is a no-op and will
  143. // not return an error. Paths that do not yet exist on the filesystem cannot be
  144. // watched.
  145. //
  146. // A watch will be automatically removed if the watched path is deleted or
  147. // renamed. The exception is the Windows backend, which doesn't remove the
  148. // watcher on renames.
  149. //
  150. // Notifications on network filesystems (NFS, SMB, FUSE, etc.) or special
  151. // filesystems (/proc, /sys, etc.) generally don't work.
  152. //
  153. // Returns [ErrClosed] if [Watcher.Close] was called.
  154. //
  155. // See [Watcher.AddWith] for a version that allows adding options.
  156. //
  157. // # Watching directories
  158. //
  159. // All files in a directory are monitored, including new files that are created
  160. // after the watcher is started. Subdirectories are not watched (i.e. it's
  161. // non-recursive).
  162. //
  163. // # Watching files
  164. //
  165. // Watching individual files (rather than directories) is generally not
  166. // recommended as many programs (especially editors) update files atomically: it
  167. // will write to a temporary file which is then moved to to destination,
  168. // overwriting the original (or some variant thereof). The watcher on the
  169. // original file is now lost, as that no longer exists.
  170. //
  171. // The upshot of this is that a power failure or crash won't leave a
  172. // half-written file.
  173. //
  174. // Watch the parent directory and use Event.Name to filter out files you're not
  175. // interested in. There is an example of this in cmd/fsnotify/file.go.
  176. func (w *Watcher) Add(name string) error { return nil }
  177. // AddWith is like [Watcher.Add], but allows adding options. When using Add()
  178. // the defaults described below are used.
  179. //
  180. // Possible options are:
  181. //
  182. // - [WithBufferSize] sets the buffer size for the Windows backend; no-op on
  183. // other platforms. The default is 64K (65536 bytes).
  184. func (w *Watcher) AddWith(name string, opts ...addOpt) error { return nil }
  185. // Remove stops monitoring the path for changes.
  186. //
  187. // Directories are always removed non-recursively. For example, if you added
  188. // /tmp/dir and /tmp/dir/subdir then you will need to remove both.
  189. //
  190. // Removing a path that has not yet been added returns [ErrNonExistentWatch].
  191. //
  192. // Returns nil if [Watcher.Close] was called.
  193. func (w *Watcher) Remove(name string) error { return nil }