vendor/github.com/fsnotify/fsnotify/README.md
changeset 256 6d9efbef00a9
parent 242 2a9ec03fe5a1
child 260 445e01aede7e
equal deleted inserted replaced
255:4f153a23adab 256:6d9efbef00a9
     8 go get -u golang.org/x/sys/...
     8 go get -u golang.org/x/sys/...
     9 ```
     9 ```
    10 
    10 
    11 Cross platform: Windows, Linux, BSD and macOS.
    11 Cross platform: Windows, Linux, BSD and macOS.
    12 
    12 
    13 |Adapter   |OS        |Status    |
    13 | Adapter               | OS                               | Status                                                                                                                          |
    14 |----------|----------|----------|
    14 | --------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
    15 |inotify   |Linux 2.6.27 or later, Android\*|Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify)|
    15 | inotify               | Linux 2.6.27 or later, Android\* | Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify) |
    16 |kqueue    |BSD, macOS, iOS\*|Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify)|
    16 | kqueue                | BSD, macOS, iOS\*                | Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify) |
    17 |ReadDirectoryChangesW|Windows|Supported [![Build status](https://ci.appveyor.com/api/projects/status/ivwjubaih4r0udeh/branch/master?svg=true)](https://ci.appveyor.com/project/NathanYoungman/fsnotify/branch/master)|
    17 | ReadDirectoryChangesW | Windows                          | Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify) |
    18 |FSEvents  |macOS         |[Planned](https://github.com/fsnotify/fsnotify/issues/11)|
    18 | FSEvents              | macOS                            | [Planned](https://github.com/fsnotify/fsnotify/issues/11)                                                                       |
    19 |FEN       |Solaris 11    |[In Progress](https://github.com/fsnotify/fsnotify/issues/12)|
    19 | FEN                   | Solaris 11                       | [In Progress](https://github.com/fsnotify/fsnotify/issues/12)                                                                   |
    20 |fanotify  |Linux 2.6.37+ | |
    20 | fanotify              | Linux 2.6.37+                    | [Planned](https://github.com/fsnotify/fsnotify/issues/114)                                                                      |
    21 |USN Journals |Windows    |[Maybe](https://github.com/fsnotify/fsnotify/issues/53)|
    21 | USN Journals          | Windows                          | [Maybe](https://github.com/fsnotify/fsnotify/issues/53)                                                                         |
    22 |Polling   |*All*         |[Maybe](https://github.com/fsnotify/fsnotify/issues/9)|
    22 | Polling               | *All*                            | [Maybe](https://github.com/fsnotify/fsnotify/issues/9)                                                                          |
    23 
    23 
    24 \* Android and iOS are untested.
    24 \* Android and iOS are untested.
    25 
    25 
    26 Please see [the documentation](https://godoc.org/github.com/fsnotify/fsnotify) and consult the [FAQ](#faq) for usage information.
    26 Please see [the documentation](https://godoc.org/github.com/fsnotify/fsnotify) and consult the [FAQ](#faq) for usage information.
    27 
    27 
    30 fsnotify is a fork of [howeyc/fsnotify](https://godoc.org/github.com/howeyc/fsnotify) with a new API as of v1.0. The API is based on [this design document](http://goo.gl/MrYxyA). 
    30 fsnotify is a fork of [howeyc/fsnotify](https://godoc.org/github.com/howeyc/fsnotify) with a new API as of v1.0. The API is based on [this design document](http://goo.gl/MrYxyA). 
    31 
    31 
    32 All [releases](https://github.com/fsnotify/fsnotify/releases) are tagged based on [Semantic Versioning](http://semver.org/). Further API changes are [planned](https://github.com/fsnotify/fsnotify/milestones), and will be tagged with a new major revision number.
    32 All [releases](https://github.com/fsnotify/fsnotify/releases) are tagged based on [Semantic Versioning](http://semver.org/). Further API changes are [planned](https://github.com/fsnotify/fsnotify/milestones), and will be tagged with a new major revision number.
    33 
    33 
    34 Go 1.6 supports dependencies located in the `vendor/` folder. Unless you are creating a library, it is recommended that you copy fsnotify into `vendor/github.com/fsnotify/fsnotify` within your project, and likewise for `golang.org/x/sys`.
    34 Go 1.6 supports dependencies located in the `vendor/` folder. Unless you are creating a library, it is recommended that you copy fsnotify into `vendor/github.com/fsnotify/fsnotify` within your project, and likewise for `golang.org/x/sys`.
       
    35 
       
    36 ## Usage
       
    37 
       
    38 ```go
       
    39 package main
       
    40 
       
    41 import (
       
    42 	"log"
       
    43 
       
    44 	"github.com/fsnotify/fsnotify"
       
    45 )
       
    46 
       
    47 func main() {
       
    48 	watcher, err := fsnotify.NewWatcher()
       
    49 	if err != nil {
       
    50 		log.Fatal(err)
       
    51 	}
       
    52 	defer watcher.Close()
       
    53 
       
    54 	done := make(chan bool)
       
    55 	go func() {
       
    56 		for {
       
    57 			select {
       
    58 			case event, ok := <-watcher.Events:
       
    59 				if !ok {
       
    60 					return
       
    61 				}
       
    62 				log.Println("event:", event)
       
    63 				if event.Op&fsnotify.Write == fsnotify.Write {
       
    64 					log.Println("modified file:", event.Name)
       
    65 				}
       
    66 			case err, ok := <-watcher.Errors:
       
    67 				if !ok {
       
    68 					return
       
    69 				}
       
    70 				log.Println("error:", err)
       
    71 			}
       
    72 		}
       
    73 	}()
       
    74 
       
    75 	err = watcher.Add("/tmp/foo")
       
    76 	if err != nil {
       
    77 		log.Fatal(err)
       
    78 	}
       
    79 	<-done
       
    80 }
       
    81 ```
    35 
    82 
    36 ## Contributing
    83 ## Contributing
    37 
    84 
    38 Please refer to [CONTRIBUTING][] before opening an issue or pull request.
    85 Please refer to [CONTRIBUTING][] before opening an issue or pull request.
    39 
    86 
    63 
   110 
    64 There are OS-specific limits as to how many watches can be created:
   111 There are OS-specific limits as to how many watches can be created:
    65 * Linux: /proc/sys/fs/inotify/max_user_watches contains the limit, reaching this limit results in a "no space left on device" error.
   112 * Linux: /proc/sys/fs/inotify/max_user_watches contains the limit, reaching this limit results in a "no space left on device" error.
    66 * BSD / OSX: sysctl variables "kern.maxfiles" and "kern.maxfilesperproc", reaching these limits results in a "too many open files" error.
   113 * BSD / OSX: sysctl variables "kern.maxfiles" and "kern.maxfilesperproc", reaching these limits results in a "too many open files" error.
    67 
   114 
       
   115 **Why don't notifications work with NFS filesystems or filesystem in userspace (FUSE)?**
       
   116 
       
   117 fsnotify requires support from underlying OS to work. The current NFS protocol does not provide network level support for file notifications.
       
   118 
    68 [#62]: https://github.com/howeyc/fsnotify/issues/62
   119 [#62]: https://github.com/howeyc/fsnotify/issues/62
    69 [#18]: https://github.com/fsnotify/fsnotify/issues/18
   120 [#18]: https://github.com/fsnotify/fsnotify/issues/18
    70 [#11]: https://github.com/fsnotify/fsnotify/issues/11
   121 [#11]: https://github.com/fsnotify/fsnotify/issues/11
    71 [#7]: https://github.com/howeyc/fsnotify/issues/7
   122 [#7]: https://github.com/howeyc/fsnotify/issues/7
    72 
   123