Browse Source

Added Windows Support

Wirecog, LLC 4 years ago
parent
commit
fba4bbc277
100 changed files with 8292 additions and 20 deletions
  1. 3
    4
      Readme.md
  2. 1
    16
      kick.go
  3. 26
    0
      startstop_unixlike.go
  4. 23
    0
      startstop_windows.go
  5. 5
    0
      vendor/github.com/fsnotify/fsnotify/.editorconfig
  6. 11
    0
      vendor/github.com/fsnotify/fsnotify/.github/ISSUE_TEMPLATE.md
  7. 8
    0
      vendor/github.com/fsnotify/fsnotify/.github/PULL_REQUEST_TEMPLATE.md
  8. 6
    0
      vendor/github.com/fsnotify/fsnotify/.gitignore
  9. 30
    0
      vendor/github.com/fsnotify/fsnotify/.travis.yml
  10. 46
    0
      vendor/github.com/fsnotify/fsnotify/AUTHORS
  11. 307
    0
      vendor/github.com/fsnotify/fsnotify/CHANGELOG.md
  12. 77
    0
      vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md
  13. 28
    0
      vendor/github.com/fsnotify/fsnotify/LICENSE
  14. 79
    0
      vendor/github.com/fsnotify/fsnotify/README.md
  15. 42
    0
      vendor/github.com/fsnotify/fsnotify/example_test.go
  16. 37
    0
      vendor/github.com/fsnotify/fsnotify/fen.go
  17. 66
    0
      vendor/github.com/fsnotify/fsnotify/fsnotify.go
  18. 40
    0
      vendor/github.com/fsnotify/fsnotify/fsnotify_test.go
  19. 337
    0
      vendor/github.com/fsnotify/fsnotify/inotify.go
  20. 187
    0
      vendor/github.com/fsnotify/fsnotify/inotify_poller.go
  21. 229
    0
      vendor/github.com/fsnotify/fsnotify/inotify_poller_test.go
  22. 449
    0
      vendor/github.com/fsnotify/fsnotify/inotify_test.go
  23. 147
    0
      vendor/github.com/fsnotify/fsnotify/integration_darwin_test.go
  24. 1237
    0
      vendor/github.com/fsnotify/fsnotify/integration_test.go
  25. 503
    0
      vendor/github.com/fsnotify/fsnotify/kqueue.go
  26. 11
    0
      vendor/github.com/fsnotify/fsnotify/open_mode_bsd.go
  27. 12
    0
      vendor/github.com/fsnotify/fsnotify/open_mode_darwin.go
  28. 561
    0
      vendor/github.com/fsnotify/fsnotify/windows.go
  29. 10
    0
      vendor/golang.org/x/sys/.gitattributes
  30. 2
    0
      vendor/golang.org/x/sys/.gitignore
  31. 3
    0
      vendor/golang.org/x/sys/AUTHORS
  32. 31
    0
      vendor/golang.org/x/sys/CONTRIBUTING.md
  33. 3
    0
      vendor/golang.org/x/sys/CONTRIBUTORS
  34. 27
    0
      vendor/golang.org/x/sys/LICENSE
  35. 22
    0
      vendor/golang.org/x/sys/PATENTS
  36. 3
    0
      vendor/golang.org/x/sys/README
  37. 1
    0
      vendor/golang.org/x/sys/codereview.cfg
  38. 8
    0
      vendor/golang.org/x/sys/plan9/asm.s
  39. 30
    0
      vendor/golang.org/x/sys/plan9/asm_plan9_386.s
  40. 30
    0
      vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s
  41. 70
    0
      vendor/golang.org/x/sys/plan9/const_plan9.go
  42. 212
    0
      vendor/golang.org/x/sys/plan9/dir_plan9.go
  43. 27
    0
      vendor/golang.org/x/sys/plan9/env_plan9.go
  44. 14
    0
      vendor/golang.org/x/sys/plan9/env_unset.go
  45. 50
    0
      vendor/golang.org/x/sys/plan9/errors_plan9.go
  46. 138
    0
      vendor/golang.org/x/sys/plan9/mkall.sh
  47. 246
    0
      vendor/golang.org/x/sys/plan9/mkerrors.sh
  48. 319
    0
      vendor/golang.org/x/sys/plan9/mksyscall.pl
  49. 23
    0
      vendor/golang.org/x/sys/plan9/mksysnum_plan9.sh
  50. 21
    0
      vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go
  51. 23
    0
      vendor/golang.org/x/sys/plan9/pwd_plan9.go
  52. 30
    0
      vendor/golang.org/x/sys/plan9/race.go
  53. 25
    0
      vendor/golang.org/x/sys/plan9/race0.go
  54. 22
    0
      vendor/golang.org/x/sys/plan9/str.go
  55. 74
    0
      vendor/golang.org/x/sys/plan9/syscall.go
  56. 349
    0
      vendor/golang.org/x/sys/plan9/syscall_plan9.go
  57. 33
    0
      vendor/golang.org/x/sys/plan9/syscall_test.go
  58. 292
    0
      vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go
  59. 292
    0
      vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go
  60. 49
    0
      vendor/golang.org/x/sys/plan9/zsysnum_plan9.go
  61. 1
    0
      vendor/golang.org/x/sys/unix/.gitignore
  62. 173
    0
      vendor/golang.org/x/sys/unix/README.md
  63. 29
    0
      vendor/golang.org/x/sys/unix/asm_darwin_386.s
  64. 29
    0
      vendor/golang.org/x/sys/unix/asm_darwin_amd64.s
  65. 30
    0
      vendor/golang.org/x/sys/unix/asm_darwin_arm.s
  66. 30
    0
      vendor/golang.org/x/sys/unix/asm_darwin_arm64.s
  67. 29
    0
      vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s
  68. 29
    0
      vendor/golang.org/x/sys/unix/asm_freebsd_386.s
  69. 29
    0
      vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s
  70. 29
    0
      vendor/golang.org/x/sys/unix/asm_freebsd_arm.s
  71. 35
    0
      vendor/golang.org/x/sys/unix/asm_linux_386.s
  72. 29
    0
      vendor/golang.org/x/sys/unix/asm_linux_amd64.s
  73. 29
    0
      vendor/golang.org/x/sys/unix/asm_linux_arm.s
  74. 24
    0
      vendor/golang.org/x/sys/unix/asm_linux_arm64.s
  75. 28
    0
      vendor/golang.org/x/sys/unix/asm_linux_mips64x.s
  76. 31
    0
      vendor/golang.org/x/sys/unix/asm_linux_mipsx.s
  77. 28
    0
      vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s
  78. 28
    0
      vendor/golang.org/x/sys/unix/asm_linux_s390x.s
  79. 29
    0
      vendor/golang.org/x/sys/unix/asm_netbsd_386.s
  80. 29
    0
      vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s
  81. 29
    0
      vendor/golang.org/x/sys/unix/asm_netbsd_arm.s
  82. 29
    0
      vendor/golang.org/x/sys/unix/asm_openbsd_386.s
  83. 29
    0
      vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s
  84. 17
    0
      vendor/golang.org/x/sys/unix/asm_solaris_amd64.s
  85. 35
    0
      vendor/golang.org/x/sys/unix/bluetooth_linux.go
  86. 13
    0
      vendor/golang.org/x/sys/unix/constants.go
  87. 121
    0
      vendor/golang.org/x/sys/unix/creds_test.go
  88. 102
    0
      vendor/golang.org/x/sys/unix/dirent.go
  89. 9
    0
      vendor/golang.org/x/sys/unix/endian_big.go
  90. 9
    0
      vendor/golang.org/x/sys/unix/endian_little.go
  91. 27
    0
      vendor/golang.org/x/sys/unix/env_unix.go
  92. 14
    0
      vendor/golang.org/x/sys/unix/env_unset.go
  93. 9
    0
      vendor/golang.org/x/sys/unix/export_test.go
  94. 24
    0
      vendor/golang.org/x/sys/unix/flock.go
  95. 13
    0
      vendor/golang.org/x/sys/unix/flock_linux_32bit.go
  96. 46
    0
      vendor/golang.org/x/sys/unix/gccgo.go
  97. 41
    0
      vendor/golang.org/x/sys/unix/gccgo_c.c
  98. 20
    0
      vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go
  99. 20
    0
      vendor/golang.org/x/sys/unix/gccgo_linux_sparc64.go
  100. 0
    0
      vendor/golang.org/x/sys/unix/linux/Dockerfile

+ 3
- 4
Readme.md View File

@@ -10,13 +10,12 @@ An *instant kickstart* consists of a recompilation of the Go code and a restart
10 10
 
11 11
 Kick comes with the ability to take both the `go` and `gopherjs` commands into consideration when performing the *instant kickstart*.
12 12
 
13
-Please note, that Kick, currently works on Unix-like operating systems (e.g., BSD, Linux, Mac OS) only. 
14
-
15
-Kick doesn't work on Windows, due to some [technical limitations](https://github.com/fsnotify/fsnotify/issues/53).
13
+## Supported Operating Systems
14
+Kick works on Windows and Unix-like operating systems (e.g., BSD, Linux, Mac OS).
16 15
 
17 16
 ## Installation
18 17
 
19
-Before installing Kick, it is recommended, to install the barebones [isogoapp](https://github.com/isomorphicgo/isogoapp) first – since it will provide you an example of how to use kick.
18
+Before installing Kick, it is recommended, to install the barebones [isogoapp](https://github.com/isomorphicgo/isogoapp) first – since it will provide you with an example of how to use kick.
20 19
 
21 20
 ### Get Kick
22 21
 `go get -u github.com/isomorphicgo/kick`

+ 1
- 16
kick.go View File

@@ -13,7 +13,6 @@ import (
13 13
 	"os/exec"
14 14
 	"os/signal"
15 15
 	"path/filepath"
16
-	"syscall"
17 16
 
18 17
 	"github.com/fsnotify/fsnotify"
19 18
 )
@@ -22,7 +21,7 @@ var appPath string
22 21
 var mainSourceFile string
23 22
 var gopherjsAppPath string
24 23
 
25
-func start() *exec.Cmd {
24
+func buildGopherJSProject() {
26 25
 
27 26
 	if gopherjsAppPath != "" {
28 27
 
@@ -39,20 +38,6 @@ func start() *exec.Cmd {
39 38
 		}
40 39
 	}
41 40
 
42
-	cmd := exec.Command("go", "run", appPath+"/"+mainSourceFile)
43
-	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
44
-	cmd.Stdout = os.Stdout
45
-	cmd.Stderr = os.Stderr
46
-	cmd.Start()
47
-	return cmd
48
-
49
-}
50
-
51
-func stop(cmd *exec.Cmd) {
52
-	pgid, err := syscall.Getpgid(cmd.Process.Pid)
53
-	if err == nil {
54
-		syscall.Kill(-pgid, 15)
55
-	}
56 41
 }
57 42
 
58 43
 func restart(cmd *exec.Cmd) *exec.Cmd {

+ 26
- 0
startstop_unixlike.go View File

@@ -0,0 +1,26 @@
1
+// +build !windows
2
+
3
+package main
4
+
5
+import (
6
+	"os"
7
+	"os/exec"
8
+	"syscall"
9
+)
10
+
11
+func start() *exec.Cmd {
12
+	buildGopherJSProject()
13
+	cmd := exec.Command("go", "run", appPath+"/"+mainSourceFile)
14
+	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
15
+	cmd.Stdout = os.Stdout
16
+	cmd.Stderr = os.Stderr
17
+	cmd.Start()
18
+	return cmd
19
+}
20
+
21
+func stop(cmd *exec.Cmd) {
22
+	pgid, err := syscall.Getpgid(cmd.Process.Pid)
23
+	if err == nil {
24
+		syscall.Kill(-pgid, 15)
25
+	}
26
+}

+ 23
- 0
startstop_windows.go View File

@@ -0,0 +1,23 @@
1
+// +build windows
2
+
3
+package main
4
+
5
+import (
6
+	"os"
7
+	"os/exec"
8
+	"strconv"
9
+)
10
+
11
+func start() *exec.Cmd {
12
+	buildGopherJSProject()
13
+	cmd := exec.Command("go", "run", appPath+"/"+mainSourceFile)
14
+	cmd.Stdout = os.Stdout
15
+	cmd.Stderr = os.Stderr
16
+	cmd.Start()
17
+	return cmd
18
+}
19
+
20
+func stop(cmd *exec.Cmd) {
21
+	stop := exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(cmd.Process.Pid))
22
+	stop.Run()
23
+}

+ 5
- 0
vendor/github.com/fsnotify/fsnotify/.editorconfig View File

@@ -0,0 +1,5 @@
1
+root = true
2
+
3
+[*]
4
+indent_style = tab
5
+indent_size = 4

+ 11
- 0
vendor/github.com/fsnotify/fsnotify/.github/ISSUE_TEMPLATE.md View File

@@ -0,0 +1,11 @@
1
+Before reporting an issue, please ensure you are using the latest release of fsnotify.
2
+
3
+### Which operating system (GOOS) and version are you using?
4
+
5
+Linux: lsb_release -a
6
+macOS: sw_vers
7
+Windows: systeminfo | findstr /B /C:OS
8
+
9
+### Please describe the issue that occurred.
10
+
11
+### Are you able to reproduce the issue? Please provide steps to reproduce and a code sample if possible.

+ 8
- 0
vendor/github.com/fsnotify/fsnotify/.github/PULL_REQUEST_TEMPLATE.md View File

@@ -0,0 +1,8 @@
1
+#### What does this pull request do?
2
+
3
+
4
+#### Where should the reviewer start?
5
+
6
+
7
+#### How should this be manually tested?
8
+

+ 6
- 0
vendor/github.com/fsnotify/fsnotify/.gitignore View File

@@ -0,0 +1,6 @@
1
+# Setup a Global .gitignore for OS and editor generated files:
2
+# https://help.github.com/articles/ignoring-files
3
+# git config --global core.excludesfile ~/.gitignore_global
4
+
5
+.vagrant
6
+*.sublime-project

+ 30
- 0
vendor/github.com/fsnotify/fsnotify/.travis.yml View File

@@ -0,0 +1,30 @@
1
+sudo: false
2
+language: go
3
+
4
+go:
5
+  - 1.8
6
+  - 1.7.x
7
+  - tip
8
+
9
+matrix:
10
+  allow_failures:
11
+    - go: tip
12
+  fast_finish: true
13
+
14
+before_script:
15
+  - go get -u github.com/golang/lint/golint
16
+
17
+script:
18
+  - go test -v --race ./...
19
+
20
+after_script:
21
+  - test -z "$(gofmt -s -l -w . | tee /dev/stderr)"
22
+  - test -z "$(golint ./...     | tee /dev/stderr)"
23
+  - go vet ./...
24
+
25
+os:
26
+  - linux
27
+  - osx
28
+
29
+notifications:
30
+  email: false

+ 46
- 0
vendor/github.com/fsnotify/fsnotify/AUTHORS View File

@@ -0,0 +1,46 @@
1
+# Names should be added to this file as
2
+#	Name or Organization <email address>
3
+# The email address is not required for organizations.
4
+
5
+# You can update this list using the following command:
6
+#
7
+#   $ git shortlog -se | awk '{print $2 " " $3 " " $4}'
8
+
9
+# Please keep the list sorted.
10
+
11
+Adrien Bustany <adrien@bustany.org>
12
+Amit Krishnan <amit.krishnan@oracle.com>
13
+Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
14
+Bruno Bigras <bigras.bruno@gmail.com>
15
+Caleb Spare <cespare@gmail.com>
16
+Case Nelson <case@teammating.com>
17
+Chris Howey <chris@howey.me> <howeyc@gmail.com>
18
+Christoffer Buchholz <christoffer.buchholz@gmail.com>
19
+Daniel Wagner-Hall <dawagner@gmail.com>
20
+Dave Cheney <dave@cheney.net>
21
+Evan Phoenix <evan@fallingsnow.net>
22
+Francisco Souza <f@souza.cc>
23
+Hari haran <hariharan.uno@gmail.com>
24
+John C Barstow
25
+Kelvin Fo <vmirage@gmail.com>
26
+Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
27
+Matt Layher <mdlayher@gmail.com>
28
+Nathan Youngman <git@nathany.com>
29
+Patrick <patrick@dropbox.com>
30
+Paul Hammond <paul@paulhammond.org>
31
+Pawel Knap <pawelknap88@gmail.com>
32
+Pieter Droogendijk <pieter@binky.org.uk>
33
+Pursuit92 <JoshChase@techpursuit.net>
34
+Riku Voipio <riku.voipio@linaro.org>
35
+Rob Figueiredo <robfig@gmail.com>
36
+Slawek Ligus <root@ooz.ie>
37
+Soge Zhang <zhssoge@gmail.com>
38
+Tiffany Jernigan <tiffany.jernigan@intel.com>
39
+Tilak Sharma <tilaks@google.com>
40
+Travis Cline <travis.cline@gmail.com>
41
+Tudor Golubenco <tudor.g@gmail.com>
42
+Yukang <moorekang@gmail.com>
43
+bronze1man <bronze1man@gmail.com>
44
+debrando <denis.brandolini@gmail.com>
45
+henrikedwards <henrik.edwards@gmail.com>
46
+铁哥 <guotie.9@gmail.com>

+ 307
- 0
vendor/github.com/fsnotify/fsnotify/CHANGELOG.md View File

@@ -0,0 +1,307 @@
1
+# Changelog
2
+
3
+## v1.4.2 / 2016-10-10
4
+
5
+* Linux: use InotifyInit1 with IN_CLOEXEC to stop leaking a file descriptor to a child process when using fork/exec [#178](https://github.com/fsnotify/fsnotify/pull/178) (thanks @pattyshack)
6
+
7
+## v1.4.1 / 2016-10-04
8
+
9
+* Fix flaky inotify stress test on Linux [#177](https://github.com/fsnotify/fsnotify/pull/177) (thanks @pattyshack)
10
+
11
+## v1.4.0 / 2016-10-01
12
+
13
+* add a String() method to Event.Op [#165](https://github.com/fsnotify/fsnotify/pull/165) (thanks @oozie)
14
+
15
+## v1.3.1 / 2016-06-28
16
+
17
+* Windows: fix for double backslash when watching the root of a drive [#151](https://github.com/fsnotify/fsnotify/issues/151) (thanks @brunoqc)
18
+
19
+## v1.3.0 / 2016-04-19
20
+
21
+* Support linux/arm64 by [patching](https://go-review.googlesource.com/#/c/21971/) x/sys/unix and switching to to it from syscall (thanks @suihkulokki) [#135](https://github.com/fsnotify/fsnotify/pull/135)
22
+
23
+## v1.2.10 / 2016-03-02
24
+
25
+* Fix golint errors in windows.go [#121](https://github.com/fsnotify/fsnotify/pull/121) (thanks @tiffanyfj)
26
+
27
+## v1.2.9 / 2016-01-13
28
+
29
+kqueue: Fix logic for CREATE after REMOVE [#111](https://github.com/fsnotify/fsnotify/pull/111) (thanks @bep)
30
+
31
+## v1.2.8 / 2015-12-17
32
+
33
+* kqueue: fix race condition in Close [#105](https://github.com/fsnotify/fsnotify/pull/105) (thanks @djui for reporting the issue and @ppknap for writing a failing test)
34
+* inotify: fix race in test
35
+* enable race detection for continuous integration (Linux, Mac, Windows)
36
+
37
+## v1.2.5 / 2015-10-17
38
+
39
+* inotify: use epoll_create1 for arm64 support (requires Linux 2.6.27 or later) [#100](https://github.com/fsnotify/fsnotify/pull/100) (thanks @suihkulokki)
40
+* inotify: fix path leaks [#73](https://github.com/fsnotify/fsnotify/pull/73) (thanks @chamaken)
41
+* kqueue: watch for rename events on subdirectories [#83](https://github.com/fsnotify/fsnotify/pull/83) (thanks @guotie)
42
+* kqueue: avoid infinite loops from symlinks cycles [#101](https://github.com/fsnotify/fsnotify/pull/101) (thanks @illicitonion)
43
+
44
+## v1.2.1 / 2015-10-14
45
+
46
+* kqueue: don't watch named pipes [#98](https://github.com/fsnotify/fsnotify/pull/98) (thanks @evanphx)
47
+
48
+## v1.2.0 / 2015-02-08
49
+
50
+* inotify: use epoll to wake up readEvents [#66](https://github.com/fsnotify/fsnotify/pull/66) (thanks @PieterD)
51
+* inotify: closing watcher should now always shut down goroutine [#63](https://github.com/fsnotify/fsnotify/pull/63) (thanks @PieterD)
52
+* kqueue: close kqueue after removing watches, fixes [#59](https://github.com/fsnotify/fsnotify/issues/59)
53
+
54
+## v1.1.1 / 2015-02-05
55
+
56
+* inotify: Retry read on EINTR [#61](https://github.com/fsnotify/fsnotify/issues/61) (thanks @PieterD)
57
+
58
+## v1.1.0 / 2014-12-12
59
+
60
+* kqueue: rework internals [#43](https://github.com/fsnotify/fsnotify/pull/43)
61
+    * add low-level functions
62
+    * only need to store flags on directories
63
+    * less mutexes [#13](https://github.com/fsnotify/fsnotify/issues/13)
64
+    * done can be an unbuffered channel
65
+    * remove calls to os.NewSyscallError
66
+* More efficient string concatenation for Event.String() [#52](https://github.com/fsnotify/fsnotify/pull/52) (thanks @mdlayher)
67
+* kqueue: fix regression in  rework causing subdirectories to be watched [#48](https://github.com/fsnotify/fsnotify/issues/48)
68
+* kqueue: cleanup internal watch before sending remove event [#51](https://github.com/fsnotify/fsnotify/issues/51)
69
+
70
+## v1.0.4 / 2014-09-07
71
+
72
+* kqueue: add dragonfly to the build tags.
73
+* Rename source code files, rearrange code so exported APIs are at the top.
74
+* Add done channel to example code. [#37](https://github.com/fsnotify/fsnotify/pull/37) (thanks @chenyukang)
75
+
76
+## v1.0.3 / 2014-08-19
77
+
78
+* [Fix] Windows MOVED_TO now translates to Create like on BSD and Linux. [#36](https://github.com/fsnotify/fsnotify/issues/36)
79
+
80
+## v1.0.2 / 2014-08-17
81
+
82
+* [Fix] Missing create events on macOS. [#14](https://github.com/fsnotify/fsnotify/issues/14) (thanks @zhsso)
83
+* [Fix] Make ./path and path equivalent. (thanks @zhsso)
84
+
85
+## v1.0.0 / 2014-08-15
86
+
87
+* [API] Remove AddWatch on Windows, use Add.
88
+* Improve documentation for exported identifiers. [#30](https://github.com/fsnotify/fsnotify/issues/30)
89
+* Minor updates based on feedback from golint.
90
+
91
+## dev / 2014-07-09
92
+
93
+* Moved to [github.com/fsnotify/fsnotify](https://github.com/fsnotify/fsnotify).
94
+* Use os.NewSyscallError instead of returning errno (thanks @hariharan-uno)
95
+
96
+## dev / 2014-07-04
97
+
98
+* kqueue: fix incorrect mutex used in Close()
99
+* Update example to demonstrate usage of Op.
100
+
101
+## dev / 2014-06-28
102
+
103
+* [API] Don't set the Write Op for attribute notifications [#4](https://github.com/fsnotify/fsnotify/issues/4)
104
+* Fix for String() method on Event (thanks Alex Brainman)
105
+* Don't build on Plan 9 or Solaris (thanks @4ad)
106
+
107
+## dev / 2014-06-21
108
+
109
+* Events channel of type Event rather than *Event.
110
+* [internal] use syscall constants directly for inotify and kqueue.
111
+* [internal] kqueue: rename events to kevents and fileEvent to event.
112
+
113
+## dev / 2014-06-19
114
+
115
+* Go 1.3+ required on Windows (uses syscall.ERROR_MORE_DATA internally).
116
+* [internal] remove cookie from Event struct (unused).
117
+* [internal] Event struct has the same definition across every OS.
118
+* [internal] remove internal watch and removeWatch methods.
119
+
120
+## dev / 2014-06-12
121
+
122
+* [API] Renamed Watch() to Add() and RemoveWatch() to Remove().
123
+* [API] Pluralized channel names: Events and Errors.
124
+* [API] Renamed FileEvent struct to Event.
125
+* [API] Op constants replace methods like IsCreate().
126
+
127
+## dev / 2014-06-12
128
+
129
+* Fix data race on kevent buffer (thanks @tilaks) [#98](https://github.com/howeyc/fsnotify/pull/98)
130
+
131
+## dev / 2014-05-23
132
+
133
+* [API] Remove current implementation of WatchFlags.
134
+    * current implementation doesn't take advantage of OS for efficiency
135
+    * provides little benefit over filtering events as they are received, but has  extra bookkeeping and mutexes
136
+    * no tests for the current implementation
137
+    * not fully implemented on Windows [#93](https://github.com/howeyc/fsnotify/issues/93#issuecomment-39285195)
138
+
139
+## v0.9.3 / 2014-12-31
140
+
141
+* kqueue: cleanup internal watch before sending remove event [#51](https://github.com/fsnotify/fsnotify/issues/51)
142
+
143
+## v0.9.2 / 2014-08-17
144
+
145
+* [Backport] Fix missing create events on macOS. [#14](https://github.com/fsnotify/fsnotify/issues/14) (thanks @zhsso)
146
+
147
+## v0.9.1 / 2014-06-12
148
+
149
+* Fix data race on kevent buffer (thanks @tilaks) [#98](https://github.com/howeyc/fsnotify/pull/98)
150
+
151
+## v0.9.0 / 2014-01-17
152
+
153
+* IsAttrib() for events that only concern a file's metadata [#79][] (thanks @abustany)
154
+* [Fix] kqueue: fix deadlock [#77][] (thanks @cespare)
155
+* [NOTICE] Development has moved to `code.google.com/p/go.exp/fsnotify` in preparation for inclusion in the Go standard library.
156
+
157
+## v0.8.12 / 2013-11-13
158
+
159
+* [API] Remove FD_SET and friends from Linux adapter
160
+
161
+## v0.8.11 / 2013-11-02
162
+
163
+* [Doc] Add Changelog [#72][] (thanks @nathany)
164
+* [Doc] Spotlight and double modify events on macOS [#62][] (reported by @paulhammond)
165
+
166
+## v0.8.10 / 2013-10-19
167
+
168
+* [Fix] kqueue: remove file watches when parent directory is removed [#71][] (reported by @mdwhatcott)
169
+* [Fix] kqueue: race between Close and readEvents [#70][] (reported by @bernerdschaefer)
170
+* [Doc] specify OS-specific limits in README (thanks @debrando)
171
+
172
+## v0.8.9 / 2013-09-08
173
+
174
+* [Doc] Contributing (thanks @nathany)
175
+* [Doc] update package path in example code [#63][] (thanks @paulhammond)
176
+* [Doc] GoCI badge in README (Linux only) [#60][]
177
+* [Doc] Cross-platform testing with Vagrant  [#59][] (thanks @nathany)
178
+
179
+## v0.8.8 / 2013-06-17
180
+
181
+* [Fix] Windows: handle `ERROR_MORE_DATA` on Windows [#49][] (thanks @jbowtie)
182
+
183
+## v0.8.7 / 2013-06-03
184
+
185
+* [API] Make syscall flags internal
186
+* [Fix] inotify: ignore event changes
187
+* [Fix] race in symlink test [#45][] (reported by @srid)
188
+* [Fix] tests on Windows
189
+* lower case error messages
190
+
191
+## v0.8.6 / 2013-05-23
192
+
193
+* kqueue: Use EVT_ONLY flag on Darwin
194
+* [Doc] Update README with full example
195
+
196
+## v0.8.5 / 2013-05-09
197
+
198
+* [Fix] inotify: allow monitoring of "broken" symlinks (thanks @tsg)
199
+
200
+## v0.8.4 / 2013-04-07
201
+
202
+* [Fix] kqueue: watch all file events [#40][] (thanks @ChrisBuchholz)
203
+
204
+## v0.8.3 / 2013-03-13
205
+
206
+* [Fix] inoitfy/kqueue memory leak [#36][] (reported by @nbkolchin)
207
+* [Fix] kqueue: use fsnFlags for watching a directory [#33][] (reported by @nbkolchin)
208
+
209
+## v0.8.2 / 2013-02-07
210
+
211
+* [Doc] add Authors
212
+* [Fix] fix data races for map access [#29][] (thanks @fsouza)
213
+
214
+## v0.8.1 / 2013-01-09
215
+
216
+* [Fix] Windows path separators
217
+* [Doc] BSD License
218
+
219
+## v0.8.0 / 2012-11-09
220
+
221
+* kqueue: directory watching improvements (thanks @vmirage)
222
+* inotify: add `IN_MOVED_TO` [#25][] (requested by @cpisto)
223
+* [Fix] kqueue: deleting watched directory [#24][] (reported by @jakerr)
224
+
225
+## v0.7.4 / 2012-10-09
226
+
227
+* [Fix] inotify: fixes from https://codereview.appspot.com/5418045/ (ugorji)
228
+* [Fix] kqueue: preserve watch flags when watching for delete [#21][] (reported by @robfig)
229
+* [Fix] kqueue: watch the directory even if it isn't a new watch (thanks @robfig)
230
+* [Fix] kqueue: modify after recreation of file
231
+
232
+## v0.7.3 / 2012-09-27
233
+
234
+* [Fix] kqueue: watch with an existing folder inside the watched folder (thanks @vmirage)
235
+* [Fix] kqueue: no longer get duplicate CREATE events
236
+
237
+## v0.7.2 / 2012-09-01
238
+
239
+* kqueue: events for created directories
240
+
241
+## v0.7.1 / 2012-07-14
242
+
243
+* [Fix] for renaming files
244
+
245
+## v0.7.0 / 2012-07-02
246
+
247
+* [Feature] FSNotify flags
248
+* [Fix] inotify: Added file name back to event path
249
+
250
+## v0.6.0 / 2012-06-06
251
+
252
+* kqueue: watch files after directory created (thanks @tmc)
253
+
254
+## v0.5.1 / 2012-05-22
255
+
256
+* [Fix] inotify: remove all watches before Close()
257
+
258
+## v0.5.0 / 2012-05-03
259
+
260
+* [API] kqueue: return errors during watch instead of sending over channel
261
+* kqueue: match symlink behavior on Linux
262
+* inotify: add `DELETE_SELF` (requested by @taralx)
263
+* [Fix] kqueue: handle EINTR (reported by @robfig)
264
+* [Doc] Godoc example [#1][] (thanks @davecheney)
265
+
266
+## v0.4.0 / 2012-03-30
267
+
268
+* Go 1 released: build with go tool
269
+* [Feature] Windows support using winfsnotify
270
+* Windows does not have attribute change notifications
271
+* Roll attribute notifications into IsModify
272
+
273
+## v0.3.0 / 2012-02-19
274
+
275
+* kqueue: add files when watch directory
276
+
277
+## v0.2.0 / 2011-12-30
278
+
279
+* update to latest Go weekly code
280
+
281
+## v0.1.0 / 2011-10-19
282
+
283
+* kqueue: add watch on file creation to match inotify
284
+* kqueue: create file event
285
+* inotify: ignore `IN_IGNORED` events
286
+* event String()
287
+* linux: common FileEvent functions
288
+* initial commit
289
+
290
+[#79]: https://github.com/howeyc/fsnotify/pull/79
291
+[#77]: https://github.com/howeyc/fsnotify/pull/77
292
+[#72]: https://github.com/howeyc/fsnotify/issues/72
293
+[#71]: https://github.com/howeyc/fsnotify/issues/71
294
+[#70]: https://github.com/howeyc/fsnotify/issues/70
295
+[#63]: https://github.com/howeyc/fsnotify/issues/63
296
+[#62]: https://github.com/howeyc/fsnotify/issues/62
297
+[#60]: https://github.com/howeyc/fsnotify/issues/60
298
+[#59]: https://github.com/howeyc/fsnotify/issues/59
299
+[#49]: https://github.com/howeyc/fsnotify/issues/49
300
+[#45]: https://github.com/howeyc/fsnotify/issues/45
301
+[#40]: https://github.com/howeyc/fsnotify/issues/40
302
+[#36]: https://github.com/howeyc/fsnotify/issues/36
303
+[#33]: https://github.com/howeyc/fsnotify/issues/33
304
+[#29]: https://github.com/howeyc/fsnotify/issues/29
305
+[#25]: https://github.com/howeyc/fsnotify/issues/25
306
+[#24]: https://github.com/howeyc/fsnotify/issues/24
307
+[#21]: https://github.com/howeyc/fsnotify/issues/21

+ 77
- 0
vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md View File

@@ -0,0 +1,77 @@
1
+# Contributing
2
+
3
+## Issues
4
+
5
+* Request features and report bugs using the [GitHub Issue Tracker](https://github.com/fsnotify/fsnotify/issues).
6
+* Please indicate the platform you are using fsnotify on.
7
+* A code example to reproduce the problem is appreciated.
8
+
9
+## Pull Requests
10
+
11
+### Contributor License Agreement
12
+
13
+fsnotify is derived from code in the [golang.org/x/exp](https://godoc.org/golang.org/x/exp) package and it may be included [in the standard library](https://github.com/fsnotify/fsnotify/issues/1) in the future. Therefore fsnotify carries the same [LICENSE](https://github.com/fsnotify/fsnotify/blob/master/LICENSE) as Go. Contributors retain their copyright, so you need to fill out a short form before we can accept your contribution: [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual).
14
+
15
+Please indicate that you have signed the CLA in your pull request.
16
+
17
+### How fsnotify is Developed
18
+
19
+* Development is done on feature branches.
20
+* Tests are run on BSD, Linux, macOS and Windows.
21
+* Pull requests are reviewed and [applied to master][am] using [hub][].
22
+  * Maintainers may modify or squash commits rather than asking contributors to.
23
+* To issue a new release, the maintainers will:
24
+  * Update the CHANGELOG
25
+  * Tag a version, which will become available through gopkg.in.
26
+ 
27
+### How to Fork
28
+
29
+For smooth sailing, always use the original import path. Installing with `go get` makes this easy. 
30
+
31
+1. Install from GitHub (`go get -u github.com/fsnotify/fsnotify`)
32
+2. Create your feature branch (`git checkout -b my-new-feature`)
33
+3. Ensure everything works and the tests pass (see below)
34
+4. Commit your changes (`git commit -am 'Add some feature'`)
35
+
36
+Contribute upstream:
37
+
38
+1. Fork fsnotify on GitHub
39
+2. Add your remote (`git remote add fork git@github.com:mycompany/repo.git`)
40
+3. Push to the branch (`git push fork my-new-feature`)
41
+4. Create a new Pull Request on GitHub
42
+
43
+This workflow is [thoroughly explained by Katrina Owen](https://splice.com/blog/contributing-open-source-git-repositories-go/).
44
+
45
+### Testing
46
+
47
+fsnotify uses build tags to compile different code on Linux, BSD, macOS, and Windows.
48
+
49
+Before doing a pull request, please do your best to test your changes on multiple platforms, and list which platforms you were able/unable to test on.
50
+
51
+To aid in cross-platform testing there is a Vagrantfile for Linux and BSD.
52
+
53
+* Install [Vagrant](http://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/)
54
+* Setup [Vagrant Gopher](https://github.com/nathany/vagrant-gopher) in your `src` folder.
55
+* Run `vagrant up` from the project folder. You can also setup just one box with `vagrant up linux` or `vagrant up bsd` (note: the BSD box doesn't support Windows hosts at this time, and NFS may prompt for your host OS password)
56
+* Once setup, you can run the test suite on a given OS with a single command `vagrant ssh linux -c 'cd fsnotify/fsnotify; go test'`.
57
+* When you're done, you will want to halt or destroy the Vagrant boxes.
58
+
59
+Notice: fsnotify file system events won't trigger in shared folders. The tests get around this limitation by using the /tmp directory.
60
+
61
+Right now there is no equivalent solution for Windows and macOS, but there are Windows VMs [freely available from Microsoft](http://www.modern.ie/en-us/virtualization-tools#downloads).
62
+
63
+### Maintainers
64
+
65
+Help maintaining fsnotify is welcome. To be a maintainer:
66
+
67
+* Submit a pull request and sign the CLA as above.
68
+* You must be able to run the test suite on Mac, Windows, Linux and BSD.
69
+
70
+To keep master clean, the fsnotify project uses the "apply mail" workflow outlined in Nathaniel Talbott's post ["Merge pull request" Considered Harmful][am]. This requires installing [hub][].
71
+
72
+All code changes should be internal pull requests.
73
+
74
+Releases are tagged using [Semantic Versioning](http://semver.org/).
75
+
76
+[hub]: https://github.com/github/hub
77
+[am]: http://blog.spreedly.com/2014/06/24/merge-pull-request-considered-harmful/#.VGa5yZPF_Zs

+ 28
- 0
vendor/github.com/fsnotify/fsnotify/LICENSE View File

@@ -0,0 +1,28 @@
1
+Copyright (c) 2012 The Go Authors. All rights reserved.
2
+Copyright (c) 2012 fsnotify Authors. All rights reserved.
3
+
4
+Redistribution and use in source and binary forms, with or without
5
+modification, are permitted provided that the following conditions are
6
+met:
7
+
8
+   * Redistributions of source code must retain the above copyright
9
+notice, this list of conditions and the following disclaimer.
10
+   * Redistributions in binary form must reproduce the above
11
+copyright notice, this list of conditions and the following disclaimer
12
+in the documentation and/or other materials provided with the
13
+distribution.
14
+   * Neither the name of Google Inc. nor the names of its
15
+contributors may be used to endorse or promote products derived from
16
+this software without specific prior written permission.
17
+
18
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 79
- 0
vendor/github.com/fsnotify/fsnotify/README.md View File

@@ -0,0 +1,79 @@
1
+# File system notifications for Go
2
+
3
+[![GoDoc](https://godoc.org/github.com/fsnotify/fsnotify?status.svg)](https://godoc.org/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify)
4
+
5
+fsnotify utilizes [golang.org/x/sys](https://godoc.org/golang.org/x/sys) rather than `syscall` from the standard library. Ensure you have the latest version installed by running:
6
+
7
+```console
8
+go get -u golang.org/x/sys/...
9
+```
10
+
11
+Cross platform: Windows, Linux, BSD and macOS.
12
+
13
+|Adapter   |OS        |Status    |
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)|
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)|
18
+|FSEvents  |macOS         |[Planned](https://github.com/fsnotify/fsnotify/issues/11)|
19
+|FEN       |Solaris 11    |[In Progress](https://github.com/fsnotify/fsnotify/issues/12)|
20
+|fanotify  |Linux 2.6.37+ | |
21
+|USN Journals |Windows    |[Maybe](https://github.com/fsnotify/fsnotify/issues/53)|
22
+|Polling   |*All*         |[Maybe](https://github.com/fsnotify/fsnotify/issues/9)|
23
+
24
+\* Android and iOS are untested.
25
+
26
+Please see [the documentation](https://godoc.org/github.com/fsnotify/fsnotify) and consult the [FAQ](#faq) for usage information.
27
+
28
+## API stability
29
+
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
+
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
+
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
+## Contributing
37
+
38
+Please refer to [CONTRIBUTING][] before opening an issue or pull request.
39
+
40
+## Example
41
+
42
+See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_test.go).
43
+
44
+## FAQ
45
+
46
+**When a file is moved to another directory is it still being watched?**
47
+
48
+No (it shouldn't be, unless you are watching where it was moved to).
49
+
50
+**When I watch a directory, are all subdirectories watched as well?**
51
+
52
+No, you must add watches for any directory you want to watch (a recursive watcher is on the roadmap [#18][]).
53
+
54
+**Do I have to watch the Error and Event channels in a separate goroutine?**
55
+
56
+As of now, yes. Looking into making this single-thread friendly (see [howeyc #7][#7])
57
+
58
+**Why am I receiving multiple events for the same file on OS X?**
59
+
60
+Spotlight indexing on OS X can result in multiple events (see [howeyc #62][#62]). A temporary workaround is to add your folder(s) to the *Spotlight Privacy settings* until we have a native FSEvents implementation (see [#11][]).
61
+
62
+**How many files can be watched at once?**
63
+
64
+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.
66
+* BSD / OSX: sysctl variables "kern.maxfiles" and "kern.maxfilesperproc", reaching these limits results in a "too many open files" error.
67
+
68
+[#62]: https://github.com/howeyc/fsnotify/issues/62
69
+[#18]: https://github.com/fsnotify/fsnotify/issues/18
70
+[#11]: https://github.com/fsnotify/fsnotify/issues/11
71
+[#7]: https://github.com/howeyc/fsnotify/issues/7
72
+
73
+[contributing]: https://github.com/fsnotify/fsnotify/blob/master/CONTRIBUTING.md
74
+
75
+## Related Projects
76
+
77
+* [notify](https://github.com/rjeczalik/notify)
78
+* [fsevents](https://github.com/fsnotify/fsevents)
79
+

+ 42
- 0
vendor/github.com/fsnotify/fsnotify/example_test.go View File

@@ -0,0 +1,42 @@
1
+// Copyright 2012 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !plan9
6
+
7
+package fsnotify_test
8
+
9
+import (
10
+	"log"
11
+
12
+	"github.com/fsnotify/fsnotify"
13
+)
14
+
15
+func ExampleNewWatcher() {
16
+	watcher, err := fsnotify.NewWatcher()
17
+	if err != nil {
18
+		log.Fatal(err)
19
+	}
20
+	defer watcher.Close()
21
+
22
+	done := make(chan bool)
23
+	go func() {
24
+		for {
25
+			select {
26
+			case event := <-watcher.Events:
27
+				log.Println("event:", event)
28
+				if event.Op&fsnotify.Write == fsnotify.Write {
29
+					log.Println("modified file:", event.Name)
30
+				}
31
+			case err := <-watcher.Errors:
32
+				log.Println("error:", err)
33
+			}
34
+		}
35
+	}()
36
+
37
+	err = watcher.Add("/tmp/foo")
38
+	if err != nil {
39
+		log.Fatal(err)
40
+	}
41
+	<-done
42
+}

+ 37
- 0
vendor/github.com/fsnotify/fsnotify/fen.go View File

@@ -0,0 +1,37 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build solaris
6
+
7
+package fsnotify
8
+
9
+import (
10
+	"errors"
11
+)
12
+
13
+// Watcher watches a set of files, delivering events to a channel.
14
+type Watcher struct {
15
+	Events chan Event
16
+	Errors chan error
17
+}
18
+
19
+// NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
20
+func NewWatcher() (*Watcher, error) {
21
+	return nil, errors.New("FEN based watcher not yet supported for fsnotify\n")
22
+}
23
+
24
+// Close removes all watches and closes the events channel.
25
+func (w *Watcher) Close() error {
26
+	return nil
27
+}
28
+
29
+// Add starts watching the named file or directory (non-recursively).
30
+func (w *Watcher) Add(name string) error {
31
+	return nil
32
+}
33
+
34
+// Remove stops watching the the named file or directory (non-recursively).
35
+func (w *Watcher) Remove(name string) error {
36
+	return nil
37
+}

+ 66
- 0
vendor/github.com/fsnotify/fsnotify/fsnotify.go View File

@@ -0,0 +1,66 @@
1
+// Copyright 2012 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !plan9
6
+
7
+// Package fsnotify provides a platform-independent interface for file system notifications.
8
+package fsnotify
9
+
10
+import (
11
+	"bytes"
12
+	"errors"
13
+	"fmt"
14
+)
15
+
16
+// Event represents a single file system notification.
17
+type Event struct {
18
+	Name string // Relative path to the file or directory.
19
+	Op   Op     // File operation that triggered the event.
20
+}
21
+
22
+// Op describes a set of file operations.
23
+type Op uint32
24
+
25
+// These are the generalized file operations that can trigger a notification.
26
+const (
27
+	Create Op = 1 << iota
28
+	Write
29
+	Remove
30
+	Rename
31
+	Chmod
32
+)
33
+
34
+func (op Op) String() string {
35
+	// Use a buffer for efficient string concatenation
36
+	var buffer bytes.Buffer
37
+
38
+	if op&Create == Create {
39
+		buffer.WriteString("|CREATE")
40
+	}
41
+	if op&Remove == Remove {
42
+		buffer.WriteString("|REMOVE")
43
+	}
44
+	if op&Write == Write {
45
+		buffer.WriteString("|WRITE")
46
+	}
47
+	if op&Rename == Rename {
48
+		buffer.WriteString("|RENAME")
49
+	}
50
+	if op&Chmod == Chmod {
51
+		buffer.WriteString("|CHMOD")
52
+	}
53
+	if buffer.Len() == 0 {
54
+		return ""
55
+	}
56
+	return buffer.String()[1:] // Strip leading pipe
57
+}
58
+
59
+// String returns a string representation of the event in the form
60
+// "file: REMOVE|WRITE|..."
61
+func (e Event) String() string {
62
+	return fmt.Sprintf("%q: %s", e.Name, e.Op.String())
63
+}
64
+
65
+// Common errors that can be reported by a watcher
66
+var ErrEventOverflow = errors.New("fsnotify queue overflow")

+ 40
- 0
vendor/github.com/fsnotify/fsnotify/fsnotify_test.go View File

@@ -0,0 +1,40 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !plan9
6
+
7
+package fsnotify
8
+
9
+import "testing"
10
+
11
+func TestEventStringWithValue(t *testing.T) {
12
+	for opMask, expectedString := range map[Op]string{
13
+		Chmod | Create: `"/usr/someFile": CREATE|CHMOD`,
14
+		Rename:         `"/usr/someFile": RENAME`,
15
+		Remove:         `"/usr/someFile": REMOVE`,
16
+		Write | Chmod:  `"/usr/someFile": WRITE|CHMOD`,
17
+	} {
18
+		event := Event{Name: "/usr/someFile", Op: opMask}
19
+		if event.String() != expectedString {
20
+			t.Fatalf("Expected %s, got: %v", expectedString, event.String())
21
+		}
22
+
23
+	}
24
+}
25
+
26
+func TestEventOpStringWithValue(t *testing.T) {
27
+	expectedOpString := "WRITE|CHMOD"
28
+	event := Event{Name: "someFile", Op: Write | Chmod}
29
+	if event.Op.String() != expectedOpString {
30
+		t.Fatalf("Expected %s, got: %v", expectedOpString, event.Op.String())
31
+	}
32
+}
33
+
34
+func TestEventOpStringWithNoValue(t *testing.T) {
35
+	expectedOpString := ""
36
+	event := Event{Name: "testFile", Op: 0}
37
+	if event.Op.String() != expectedOpString {
38
+		t.Fatalf("Expected %s, got: %v", expectedOpString, event.Op.String())
39
+	}
40
+}

+ 337
- 0
vendor/github.com/fsnotify/fsnotify/inotify.go View File

@@ -0,0 +1,337 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build linux
6
+
7
+package fsnotify
8
+
9
+import (
10
+	"errors"
11
+	"fmt"
12
+	"io"
13
+	"os"
14
+	"path/filepath"
15
+	"strings"
16
+	"sync"
17
+	"unsafe"
18
+
19
+	"golang.org/x/sys/unix"
20
+)
21
+
22
+// Watcher watches a set of files, delivering events to a channel.
23
+type Watcher struct {
24
+	Events   chan Event
25
+	Errors   chan error
26
+	mu       sync.Mutex // Map access
27
+	fd       int
28
+	poller   *fdPoller
29
+	watches  map[string]*watch // Map of inotify watches (key: path)
30
+	paths    map[int]string    // Map of watched paths (key: watch descriptor)
31
+	done     chan struct{}     // Channel for sending a "quit message" to the reader goroutine
32
+	doneResp chan struct{}     // Channel to respond to Close
33
+}
34
+
35
+// NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
36
+func NewWatcher() (*Watcher, error) {
37
+	// Create inotify fd
38
+	fd, errno := unix.InotifyInit1(unix.IN_CLOEXEC)
39
+	if fd == -1 {
40
+		return nil, errno
41
+	}
42
+	// Create epoll
43
+	poller, err := newFdPoller(fd)
44
+	if err != nil {
45
+		unix.Close(fd)
46
+		return nil, err
47
+	}
48
+	w := &Watcher{
49
+		fd:       fd,
50
+		poller:   poller,
51
+		watches:  make(map[string]*watch),
52
+		paths:    make(map[int]string),
53
+		Events:   make(chan Event),
54
+		Errors:   make(chan error),
55
+		done:     make(chan struct{}),
56
+		doneResp: make(chan struct{}),
57
+	}
58
+
59
+	go w.readEvents()
60
+	return w, nil
61
+}
62
+
63
+func (w *Watcher) isClosed() bool {
64
+	select {
65
+	case <-w.done:
66
+		return true
67
+	default:
68
+		return false
69
+	}
70
+}
71
+
72
+// Close removes all watches and closes the events channel.
73
+func (w *Watcher) Close() error {
74
+	if w.isClosed() {
75
+		return nil
76
+	}
77
+
78
+	// Send 'close' signal to goroutine, and set the Watcher to closed.
79
+	close(w.done)
80
+
81
+	// Wake up goroutine
82
+	w.poller.wake()
83
+
84
+	// Wait for goroutine to close
85
+	<-w.doneResp
86
+
87
+	return nil
88
+}
89
+
90
+// Add starts watching the named file or directory (non-recursively).
91
+func (w *Watcher) Add(name string) error {
92
+	name = filepath.Clean(name)
93
+	if w.isClosed() {
94
+		return errors.New("inotify instance already closed")
95
+	}
96
+
97
+	const agnosticEvents = unix.IN_MOVED_TO | unix.IN_MOVED_FROM |
98
+		unix.IN_CREATE | unix.IN_ATTRIB | unix.IN_MODIFY |
99
+		unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF
100
+
101
+	var flags uint32 = agnosticEvents
102
+
103
+	w.mu.Lock()
104
+	defer w.mu.Unlock()
105
+	watchEntry := w.watches[name]
106
+	if watchEntry != nil {
107
+		flags |= watchEntry.flags | unix.IN_MASK_ADD
108
+	}
109
+	wd, errno := unix.InotifyAddWatch(w.fd, name, flags)
110
+	if wd == -1 {
111
+		return errno
112
+	}
113
+
114
+	if watchEntry == nil {
115
+		w.watches[name] = &watch{wd: uint32(wd), flags: flags}
116
+		w.paths[wd] = name
117
+	} else {
118
+		watchEntry.wd = uint32(wd)
119
+		watchEntry.flags = flags
120
+	}
121
+
122
+	return nil
123
+}
124
+
125
+// Remove stops watching the named file or directory (non-recursively).
126
+func (w *Watcher) Remove(name string) error {
127
+	name = filepath.Clean(name)
128
+
129
+	// Fetch the watch.
130
+	w.mu.Lock()
131
+	defer w.mu.Unlock()
132
+	watch, ok := w.watches[name]
133
+
134
+	// Remove it from inotify.
135
+	if !ok {
136
+		return fmt.Errorf("can't remove non-existent inotify watch for: %s", name)
137
+	}
138
+
139
+	// We successfully removed the watch if InotifyRmWatch doesn't return an
140
+	// error, we need to clean up our internal state to ensure it matches
141
+	// inotify's kernel state.
142
+	delete(w.paths, int(watch.wd))
143
+	delete(w.watches, name)
144
+
145
+	// inotify_rm_watch will return EINVAL if the file has been deleted;
146
+	// the inotify will already have been removed.
147
+	// watches and pathes are deleted in ignoreLinux() implicitly and asynchronously
148
+	// by calling inotify_rm_watch() below. e.g. readEvents() goroutine receives IN_IGNORE
149
+	// so that EINVAL means that the wd is being rm_watch()ed or its file removed
150
+	// by another thread and we have not received IN_IGNORE event.
151
+	success, errno := unix.InotifyRmWatch(w.fd, watch.wd)
152
+	if success == -1 {
153
+		// TODO: Perhaps it's not helpful to return an error here in every case.
154
+		// the only two possible errors are:
155
+		// EBADF, which happens when w.fd is not a valid file descriptor of any kind.
156
+		// EINVAL, which is when fd is not an inotify descriptor or wd is not a valid watch descriptor.
157
+		// Watch descriptors are invalidated when they are removed explicitly or implicitly;
158
+		// explicitly by inotify_rm_watch, implicitly when the file they are watching is deleted.
159
+		return errno
160
+	}
161
+
162
+	return nil
163
+}
164
+
165
+type watch struct {
166
+	wd    uint32 // Watch descriptor (as returned by the inotify_add_watch() syscall)
167
+	flags uint32 // inotify flags of this watch (see inotify(7) for the list of valid flags)
168
+}
169
+
170
+// readEvents reads from the inotify file descriptor, converts the
171
+// received events into Event objects and sends them via the Events channel
172
+func (w *Watcher) readEvents() {
173
+	var (
174
+		buf   [unix.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events
175
+		n     int                                  // Number of bytes read with read()
176
+		errno error                                // Syscall errno
177
+		ok    bool                                 // For poller.wait
178
+	)
179
+
180
+	defer close(w.doneResp)
181
+	defer close(w.Errors)
182
+	defer close(w.Events)
183
+	defer unix.Close(w.fd)
184
+	defer w.poller.close()
185
+
186
+	for {
187
+		// See if we have been closed.
188
+		if w.isClosed() {
189
+			return
190
+		}
191
+
192
+		ok, errno = w.poller.wait()
193
+		if errno != nil {
194
+			select {
195
+			case w.Errors <- errno:
196
+			case <-w.done:
197
+				return
198
+			}
199
+			continue
200
+		}
201
+
202
+		if !ok {
203
+			continue
204
+		}
205
+
206
+		n, errno = unix.Read(w.fd, buf[:])
207
+		// If a signal interrupted execution, see if we've been asked to close, and try again.
208
+		// http://man7.org/linux/man-pages/man7/signal.7.html :
209
+		// "Before Linux 3.8, reads from an inotify(7) file descriptor were not restartable"
210
+		if errno == unix.EINTR {
211
+			continue
212
+		}
213
+
214
+		// unix.Read might have been woken up by Close. If so, we're done.
215
+		if w.isClosed() {
216
+			return
217
+		}
218
+
219
+		if n < unix.SizeofInotifyEvent {
220
+			var err error
221
+			if n == 0 {
222
+				// If EOF is received. This should really never happen.
223
+				err = io.EOF
224
+			} else if n < 0 {
225
+				// If an error occurred while reading.
226
+				err = errno
227
+			} else {
228
+				// Read was too short.
229
+				err = errors.New("notify: short read in readEvents()")
230
+			}
231
+			select {
232
+			case w.Errors <- err:
233
+			case <-w.done:
234
+				return
235
+			}
236
+			continue
237
+		}
238
+
239
+		var offset uint32
240
+		// We don't know how many events we just read into the buffer
241
+		// While the offset points to at least one whole event...
242
+		for offset <= uint32(n-unix.SizeofInotifyEvent) {
243
+			// Point "raw" to the event in the buffer
244
+			raw := (*unix.InotifyEvent)(unsafe.Pointer(&buf[offset]))
245
+
246
+			mask := uint32(raw.Mask)
247
+			nameLen := uint32(raw.Len)
248
+
249
+			if mask&unix.IN_Q_OVERFLOW != 0 {
250
+				select {
251
+				case w.Errors <- ErrEventOverflow:
252
+				case <-w.done:
253
+					return
254
+				}
255
+			}
256
+
257
+			// If the event happened to the watched directory or the watched file, the kernel
258
+			// doesn't append the filename to the event, but we would like to always fill the
259
+			// the "Name" field with a valid filename. We retrieve the path of the watch from
260
+			// the "paths" map.
261
+			w.mu.Lock()
262
+			name, ok := w.paths[int(raw.Wd)]
263
+			// IN_DELETE_SELF occurs when the file/directory being watched is removed.
264
+			// This is a sign to clean up the maps, otherwise we are no longer in sync
265
+			// with the inotify kernel state which has already deleted the watch
266
+			// automatically.
267
+			if ok && mask&unix.IN_DELETE_SELF == unix.IN_DELETE_SELF {
268
+				delete(w.paths, int(raw.Wd))
269
+				delete(w.watches, name)
270
+			}
271
+			w.mu.Unlock()
272
+
273
+			if nameLen > 0 {
274
+				// Point "bytes" at the first byte of the filename
275
+				bytes := (*[unix.PathMax]byte)(unsafe.Pointer(&buf[offset+unix.SizeofInotifyEvent]))
276
+				// The filename is padded with NULL bytes. TrimRight() gets rid of those.
277
+				name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000")
278
+			}
279
+
280
+			event := newEvent(name, mask)
281
+
282
+			// Send the events that are not ignored on the events channel
283
+			if !event.ignoreLinux(mask) {
284
+				select {
285
+				case w.Events <- event:
286
+				case <-w.done:
287
+					return
288
+				}
289
+			}
290
+
291
+			// Move to the next event in the buffer
292
+			offset += unix.SizeofInotifyEvent + nameLen
293
+		}
294
+	}
295
+}
296
+
297
+// Certain types of events can be "ignored" and not sent over the Events
298
+// channel. Such as events marked ignore by the kernel, or MODIFY events
299
+// against files that do not exist.
300
+func (e *Event) ignoreLinux(mask uint32) bool {
301
+	// Ignore anything the inotify API says to ignore
302
+	if mask&unix.IN_IGNORED == unix.IN_IGNORED {
303
+		return true
304
+	}
305
+
306
+	// If the event is not a DELETE or RENAME, the file must exist.
307
+	// Otherwise the event is ignored.
308
+	// *Note*: this was put in place because it was seen that a MODIFY
309
+	// event was sent after the DELETE. This ignores that MODIFY and
310
+	// assumes a DELETE will come or has come if the file doesn't exist.
311
+	if !(e.Op&Remove == Remove || e.Op&Rename == Rename) {
312
+		_, statErr := os.Lstat(e.Name)
313
+		return os.IsNotExist(statErr)
314
+	}
315
+	return false
316
+}
317
+
318
+// newEvent returns an platform-independent Event based on an inotify mask.
319
+func newEvent(name string, mask uint32) Event {
320
+	e := Event{Name: name}
321
+	if mask&unix.IN_CREATE == unix.IN_CREATE || mask&unix.IN_MOVED_TO == unix.IN_MOVED_TO {
322
+		e.Op |= Create
323
+	}
324
+	if mask&unix.IN_DELETE_SELF == unix.IN_DELETE_SELF || mask&unix.IN_DELETE == unix.IN_DELETE {
325
+		e.Op |= Remove
326
+	}
327
+	if mask&unix.IN_MODIFY == unix.IN_MODIFY {
328
+		e.Op |= Write
329
+	}
330
+	if mask&unix.IN_MOVE_SELF == unix.IN_MOVE_SELF || mask&unix.IN_MOVED_FROM == unix.IN_MOVED_FROM {
331
+		e.Op |= Rename
332
+	}
333
+	if mask&unix.IN_ATTRIB == unix.IN_ATTRIB {
334
+		e.Op |= Chmod
335
+	}
336
+	return e
337
+}

+ 187
- 0
vendor/github.com/fsnotify/fsnotify/inotify_poller.go View File

@@ -0,0 +1,187 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build linux
6
+
7
+package fsnotify
8
+
9
+import (
10
+	"errors"
11
+
12
+	"golang.org/x/sys/unix"
13
+)
14
+
15
+type fdPoller struct {
16
+	fd   int    // File descriptor (as returned by the inotify_init() syscall)
17
+	epfd int    // Epoll file descriptor
18
+	pipe [2]int // Pipe for waking up
19
+}
20
+
21
+func emptyPoller(fd int) *fdPoller {
22
+	poller := new(fdPoller)
23
+	poller.fd = fd
24
+	poller.epfd = -1
25
+	poller.pipe[0] = -1
26
+	poller.pipe[1] = -1
27
+	return poller
28
+}
29
+
30
+// Create a new inotify poller.
31
+// This creates an inotify handler, and an epoll handler.
32
+func newFdPoller(fd int) (*fdPoller, error) {
33
+	var errno error
34
+	poller := emptyPoller(fd)
35
+	defer func() {
36
+		if errno != nil {
37
+			poller.close()
38
+		}
39
+	}()
40
+	poller.fd = fd
41
+
42
+	// Create epoll fd
43
+	poller.epfd, errno = unix.EpollCreate1(0)
44
+	if poller.epfd == -1 {
45
+		return nil, errno
46
+	}
47
+	// Create pipe; pipe[0] is the read end, pipe[1] the write end.
48
+	errno = unix.Pipe2(poller.pipe[:], unix.O_NONBLOCK)
49
+	if errno != nil {
50
+		return nil, errno
51
+	}
52
+
53
+	// Register inotify fd with epoll
54
+	event := unix.EpollEvent{
55
+		Fd:     int32(poller.fd),
56
+		Events: unix.EPOLLIN,
57
+	}
58
+	errno = unix.EpollCtl(poller.epfd, unix.EPOLL_CTL_ADD, poller.fd, &event)
59
+	if errno != nil {
60
+		return nil, errno
61
+	}
62
+
63
+	// Register pipe fd with epoll
64
+	event = unix.EpollEvent{
65
+		Fd:     int32(poller.pipe[0]),
66
+		Events: unix.EPOLLIN,
67
+	}
68
+	errno = unix.EpollCtl(poller.epfd, unix.EPOLL_CTL_ADD, poller.pipe[0], &event)
69
+	if errno != nil {
70
+		return nil, errno
71
+	}
72
+
73
+	return poller, nil
74
+}
75
+
76
+// Wait using epoll.
77
+// Returns true if something is ready to be read,
78
+// false if there is not.
79
+func (poller *fdPoller) wait() (bool, error) {
80
+	// 3 possible events per fd, and 2 fds, makes a maximum of 6 events.
81
+	// I don't know whether epoll_wait returns the number of events returned,
82
+	// or the total number of events ready.
83
+	// I decided to catch both by making the buffer one larger than the maximum.
84
+	events := make([]unix.EpollEvent, 7)
85
+	for {
86
+		n, errno := unix.EpollWait(poller.epfd, events, -1)
87
+		if n == -1 {
88
+			if errno == unix.EINTR {
89
+				continue
90
+			}
91
+			return false, errno
92
+		}
93
+		if n == 0 {
94
+			// If there are no events, try again.
95
+			continue
96
+		}
97
+		if n > 6 {
98
+			// This should never happen. More events were returned than should be possible.
99
+			return false, errors.New("epoll_wait returned more events than I know what to do with")
100
+		}
101
+		ready := events[:n]
102
+		epollhup := false
103
+		epollerr := false
104
+		epollin := false
105
+		for _, event := range ready {
106
+			if event.Fd == int32(poller.fd) {
107
+				if event.Events&unix.EPOLLHUP != 0 {
108
+					// This should not happen, but if it does, treat it as a wakeup.
109
+					epollhup = true
110
+				}
111
+				if event.Events&unix.EPOLLERR != 0 {
112
+					// If an error is waiting on the file descriptor, we should pretend
113
+					// something is ready to read, and let unix.Read pick up the error.
114
+					epollerr = true
115
+				}
116
+				if event.Events&unix.EPOLLIN != 0 {
117
+					// There is data to read.
118
+					epollin = true
119
+				}
120
+			}
121
+			if event.Fd == int32(poller.pipe[0]) {
122
+				if event.Events&unix.EPOLLHUP != 0 {
123
+					// Write pipe descriptor was closed, by us. This means we're closing down the
124
+					// watcher, and we should wake up.
125
+				}
126
+				if event.Events&unix.EPOLLERR != 0 {
127
+					// If an error is waiting on the pipe file descriptor.
128
+					// This is an absolute mystery, and should never ever happen.
129
+					return false, errors.New("Error on the pipe descriptor.")
130
+				}
131
+				if event.Events&unix.EPOLLIN != 0 {
132
+					// This is a regular wakeup, so we have to clear the buffer.
133
+					err := poller.clearWake()
134
+					if err != nil {
135
+						return false, err
136
+					}
137
+				}
138
+			}
139
+		}
140
+
141
+		if epollhup || epollerr || epollin {
142
+			return true, nil
143
+		}
144
+		return false, nil
145
+	}
146
+}
147
+
148
+// Close the write end of the poller.
149
+func (poller *fdPoller) wake() error {
150
+	buf := make([]byte, 1)
151
+	n, errno := unix.Write(poller.pipe[1], buf)
152
+	if n == -1 {
153
+		if errno == unix.EAGAIN {
154
+			// Buffer is full, poller will wake.
155
+			return nil
156
+		}
157
+		return errno
158
+	}
159
+	return nil
160
+}
161
+
162
+func (poller *fdPoller) clearWake() error {
163
+	// You have to be woken up a LOT in order to get to 100!
164
+	buf := make([]byte, 100)
165
+	n, errno := unix.Read(poller.pipe[0], buf)
166
+	if n == -1 {
167
+		if errno == unix.EAGAIN {
168
+			// Buffer is empty, someone else cleared our wake.
169
+			return nil
170
+		}
171
+		return errno
172
+	}
173
+	return nil
174
+}
175
+
176
+// Close all poller file descriptors, but not the one passed to it.
177
+func (poller *fdPoller) close() {
178
+	if poller.pipe[1] != -1 {
179
+		unix.Close(poller.pipe[1])
180
+	}
181
+	if poller.pipe[0] != -1 {
182
+		unix.Close(poller.pipe[0])
183
+	}
184
+	if poller.epfd != -1 {
185
+		unix.Close(poller.epfd)
186
+	}
187
+}

+ 229
- 0
vendor/github.com/fsnotify/fsnotify/inotify_poller_test.go View File

@@ -0,0 +1,229 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build linux
6
+
7
+package fsnotify
8
+
9
+import (
10
+	"testing"
11
+	"time"
12
+
13
+	"golang.org/x/sys/unix"
14
+)
15
+
16
+type testFd [2]int
17
+
18
+func makeTestFd(t *testing.T) testFd {
19
+	var tfd testFd
20
+	errno := unix.Pipe(tfd[:])
21
+	if errno != nil {
22
+		t.Fatalf("Failed to create pipe: %v", errno)
23
+	}
24
+	return tfd
25
+}
26
+
27
+func (tfd testFd) fd() int {
28
+	return tfd[0]
29
+}
30
+
31
+func (tfd testFd) closeWrite(t *testing.T) {
32
+	errno := unix.Close(tfd[1])
33
+	if errno != nil {
34
+		t.Fatalf("Failed to close write end of pipe: %v", errno)
35
+	}
36
+}
37
+
38
+func (tfd testFd) put(t *testing.T) {
39
+	buf := make([]byte, 10)
40
+	_, errno := unix.Write(tfd[1], buf)
41
+	if errno != nil {
42
+		t.Fatalf("Failed to write to pipe: %v", errno)
43
+	}
44
+}
45
+
46
+func (tfd testFd) get(t *testing.T) {
47
+	buf := make([]byte, 10)
48
+	_, errno := unix.Read(tfd[0], buf)
49
+	if errno != nil {
50
+		t.Fatalf("Failed to read from pipe: %v", errno)
51
+	}
52
+}
53
+
54
+func (tfd testFd) close() {
55
+	unix.Close(tfd[1])
56
+	unix.Close(tfd[0])
57
+}
58
+
59
+func makePoller(t *testing.T) (testFd, *fdPoller) {
60
+	tfd := makeTestFd(t)
61
+	poller, err := newFdPoller(tfd.fd())
62
+	if err != nil {
63
+		t.Fatalf("Failed to create poller: %v", err)
64
+	}
65
+	return tfd, poller
66
+}
67
+
68
+func TestPollerWithBadFd(t *testing.T) {
69
+	_, err := newFdPoller(-1)
70
+	if err != unix.EBADF {
71
+		t.Fatalf("Expected EBADF, got: %v", err)
72
+	}
73
+}
74
+
75
+func TestPollerWithData(t *testing.T) {
76
+	tfd, poller := makePoller(t)
77
+	defer tfd.close()
78
+	defer poller.close()
79
+
80
+	tfd.put(t)
81
+	ok, err := poller.wait()
82
+	if err != nil {
83
+		t.Fatalf("poller failed: %v", err)
84
+	}
85
+	if !ok {
86
+		t.Fatalf("expected poller to return true")
87
+	}
88
+	tfd.get(t)
89
+}
90
+
91
+func TestPollerWithWakeup(t *testing.T) {
92
+	tfd, poller := makePoller(t)
93
+	defer tfd.close()
94
+	defer poller.close()
95
+
96
+	err := poller.wake()
97
+	if err != nil {
98
+		t.Fatalf("wake failed: %v", err)
99
+	}
100
+	ok, err := poller.wait()
101
+	if err != nil {
102
+		t.Fatalf("poller failed: %v", err)
103
+	}
104
+	if ok {
105
+		t.Fatalf("expected poller to return false")
106
+	}
107
+}
108
+
109
+func TestPollerWithClose(t *testing.T) {
110
+	tfd, poller := makePoller(t)
111
+	defer tfd.close()
112
+	defer poller.close()
113
+
114
+	tfd.closeWrite(t)
115
+	ok, err := poller.wait()
116
+	if err != nil {
117
+		t.Fatalf("poller failed: %v", err)
118
+	}
119
+	if !ok {
120
+		t.Fatalf("expected poller to return true")
121
+	}
122
+}
123
+
124
+func TestPollerWithWakeupAndData(t *testing.T) {
125
+	tfd, poller := makePoller(t)
126
+	defer tfd.close()
127
+	defer poller.close()
128
+
129
+	tfd.put(t)
130
+	err := poller.wake()
131
+	if err != nil {
132
+		t.Fatalf("wake failed: %v", err)
133
+	}
134
+
135
+	// both data and wakeup
136
+	ok, err := poller.wait()
137
+	if err != nil {
138
+		t.Fatalf("poller failed: %v", err)
139
+	}
140
+	if !ok {
141
+		t.Fatalf("expected poller to return true")
142
+	}
143
+
144
+	// data is still in the buffer, wakeup is cleared
145
+	ok, err = poller.wait()
146
+	if err != nil {
147
+		t.Fatalf("poller failed: %v", err)
148
+	}
149
+	if !ok {
150
+		t.Fatalf("expected poller to return true")
151
+	}
152
+
153
+	tfd.get(t)
154
+	// data is gone, only wakeup now
155
+	err = poller.wake()
156
+	if err != nil {
157
+		t.Fatalf("wake failed: %v", err)
158
+	}
159
+	ok, err = poller.wait()
160
+	if err != nil {
161
+		t.Fatalf("poller failed: %v", err)
162
+	}
163
+	if ok {
164
+		t.Fatalf("expected poller to return false")
165
+	}
166
+}
167
+
168
+func TestPollerConcurrent(t *testing.T) {
169
+	tfd, poller := makePoller(t)
170
+	defer tfd.close()
171
+	defer poller.close()
172
+
173
+	oks := make(chan bool)
174
+	live := make(chan bool)
175
+	defer close(live)
176
+	go func() {
177
+		defer close(oks)
178
+		for {
179
+			ok, err := poller.wait()
180
+			if err != nil {
181
+				t.Fatalf("poller failed: %v", err)
182
+			}
183
+			oks <- ok
184
+			if !<-live {
185
+				return
186
+			}
187
+		}
188
+	}()
189
+
190
+	// Try a write
191
+	select {
192
+	case <-time.After(50 * time.Millisecond):
193
+	case <-oks:
194
+		t.Fatalf("poller did not wait")
195
+	}
196
+	tfd.put(t)
197
+	if !<-oks {
198
+		t.Fatalf("expected true")
199
+	}
200
+	tfd.get(t)
201
+	live <- true
202
+
203
+	// Try a wakeup
204
+	select {
205
+	case <-time.After(50 * time.Millisecond):
206
+	case <-oks:
207
+		t.Fatalf("poller did not wait")
208
+	}
209
+	err := poller.wake()
210
+	if err != nil {
211
+		t.Fatalf("wake failed: %v", err)
212
+	}
213
+	if <-oks {
214
+		t.Fatalf("expected false")
215
+	}
216
+	live <- true
217
+
218
+	// Try a close
219
+	select {
220
+	case <-time.After(50 * time.Millisecond):
221
+	case <-oks:
222
+		t.Fatalf("poller did not wait")
223
+	}
224
+	tfd.closeWrite(t)
225
+	if !<-oks {
226
+		t.Fatalf("expected true")
227
+	}
228
+	tfd.get(t)
229
+}

+ 449
- 0
vendor/github.com/fsnotify/fsnotify/inotify_test.go View File

@@ -0,0 +1,449 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build linux
6
+
7
+package fsnotify
8
+
9
+import (
10
+	"fmt"
11
+	"os"
12
+	"path/filepath"
13
+	"strings"
14
+	"testing"
15
+	"time"
16
+)
17
+
18
+func TestInotifyCloseRightAway(t *testing.T) {
19
+	w, err := NewWatcher()
20
+	if err != nil {
21
+		t.Fatalf("Failed to create watcher")
22
+	}
23
+
24
+	// Close immediately; it won't even reach the first unix.Read.
25
+	w.Close()
26
+
27
+	// Wait for the close to complete.
28
+	<-time.After(50 * time.Millisecond)
29
+	isWatcherReallyClosed(t, w)
30
+}
31
+
32
+func TestInotifyCloseSlightlyLater(t *testing.T) {
33
+	w, err := NewWatcher()
34
+	if err != nil {
35
+		t.Fatalf("Failed to create watcher")
36
+	}
37
+
38
+	// Wait until readEvents has reached unix.Read, and Close.
39
+	<-time.After(50 * time.Millisecond)
40
+	w.Close()
41
+
42
+	// Wait for the close to complete.
43
+	<-time.After(50 * time.Millisecond)
44
+	isWatcherReallyClosed(t, w)
45
+}
46
+
47
+func TestInotifyCloseSlightlyLaterWithWatch(t *testing.T) {
48
+	testDir := tempMkdir(t)
49
+	defer os.RemoveAll(testDir)
50
+
51
+	w, err := NewWatcher()
52
+	if err != nil {
53
+		t.Fatalf("Failed to create watcher")
54
+	}
55
+	w.Add(testDir)
56
+
57
+	// Wait until readEvents has reached unix.Read, and Close.
58
+	<-time.After(50 * time.Millisecond)
59
+	w.Close()
60
+
61
+	// Wait for the close to complete.
62
+	<-time.After(50 * time.Millisecond)
63
+	isWatcherReallyClosed(t, w)
64
+}
65
+
66
+func TestInotifyCloseAfterRead(t *testing.T) {
67
+	testDir := tempMkdir(t)
68
+	defer os.RemoveAll(testDir)
69
+
70
+	w, err := NewWatcher()
71
+	if err != nil {
72
+		t.Fatalf("Failed to create watcher")
73
+	}
74
+
75
+	err = w.Add(testDir)
76
+	if err != nil {
77
+		t.Fatalf("Failed to add .")
78
+	}
79
+
80
+	// Generate an event.
81
+	os.Create(filepath.Join(testDir, "somethingSOMETHINGsomethingSOMETHING"))
82
+
83
+	// Wait for readEvents to read the event, then close the watcher.
84
+	<-time.After(50 * time.Millisecond)
85
+	w.Close()
86
+
87
+	// Wait for the close to complete.
88
+	<-time.After(50 * time.Millisecond)
89
+	isWatcherReallyClosed(t, w)
90
+}
91
+
92
+func isWatcherReallyClosed(t *testing.T, w *Watcher) {
93
+	select {
94
+	case err, ok := <-w.Errors:
95
+		if ok {
96
+			t.Fatalf("w.Errors is not closed; readEvents is still alive after closing (error: %v)", err)
97
+		}
98
+	default:
99
+		t.Fatalf("w.Errors would have blocked; readEvents is still alive!")
100
+	}
101
+
102
+	select {
103
+	case _, ok := <-w.Events:
104
+		if ok {
105
+			t.Fatalf("w.Events is not closed; readEvents is still alive after closing")
106
+		}
107
+	default:
108
+		t.Fatalf("w.Events would have blocked; readEvents is still alive!")
109
+	}
110
+}
111
+
112
+func TestInotifyCloseCreate(t *testing.T) {
113
+	testDir := tempMkdir(t)
114
+	defer os.RemoveAll(testDir)
115
+
116
+	w, err := NewWatcher()
117
+	if err != nil {
118
+		t.Fatalf("Failed to create watcher: %v", err)
119
+	}
120
+	defer w.Close()
121
+
122
+	err = w.Add(testDir)
123
+	if err != nil {
124
+		t.Fatalf("Failed to add testDir: %v", err)
125
+	}
126
+	h, err := os.Create(filepath.Join(testDir, "testfile"))
127
+	if err != nil {
128
+		t.Fatalf("Failed to create file in testdir: %v", err)
129
+	}
130
+	h.Close()
131
+	select {
132
+	case _ = <-w.Events:
133
+	case err := <-w.Errors:
134
+		t.Fatalf("Error from watcher: %v", err)
135
+	case <-time.After(50 * time.Millisecond):
136
+		t.Fatalf("Took too long to wait for event")
137
+	}
138
+
139
+	// At this point, we've received one event, so the goroutine is ready.
140
+	// It's also blocking on unix.Read.
141
+	// Now we try to swap the file descriptor under its nose.
142
+	w.Close()
143
+	w, err = NewWatcher()
144
+	defer w.Close()
145
+	if err != nil {
146
+		t.Fatalf("Failed to create second watcher: %v", err)
147
+	}
148
+
149
+	<-time.After(50 * time.Millisecond)
150
+	err = w.Add(testDir)
151
+	if err != nil {
152
+		t.Fatalf("Error adding testDir again: %v", err)
153
+	}
154
+}
155
+
156
+// This test verifies the watcher can keep up with file creations/deletions
157
+// when under load.
158
+func TestInotifyStress(t *testing.T) {
159
+	maxNumToCreate := 1000
160
+
161
+	testDir := tempMkdir(t)
162
+	defer os.RemoveAll(testDir)
163
+	testFilePrefix := filepath.Join(testDir, "testfile")
164
+
165
+	w, err := NewWatcher()
166
+	if err != nil {
167
+		t.Fatalf("Failed to create watcher: %v", err)
168
+	}
169
+	defer w.Close()
170
+
171
+	err = w.Add(testDir)
172
+	if err != nil {
173
+		t.Fatalf("Failed to add testDir: %v", err)
174
+	}
175
+
176
+	doneChan := make(chan struct{})
177
+	// The buffer ensures that the file generation goroutine is never blocked.
178
+	errChan := make(chan error, 2*maxNumToCreate)
179
+
180
+	go func() {
181
+		for i := 0; i < maxNumToCreate; i++ {
182
+			testFile := fmt.Sprintf("%s%d", testFilePrefix, i)
183
+
184
+			handle, err := os.Create(testFile)
185
+			if err != nil {
186
+				errChan <- fmt.Errorf("Create failed: %v", err)
187
+				continue
188
+			}
189
+
190
+			err = handle.Close()
191
+			if err != nil {
192
+				errChan <- fmt.Errorf("Close failed: %v", err)
193
+				continue
194
+			}
195
+		}
196
+
197
+		// If we delete a newly created file too quickly, inotify will skip the
198
+		// create event and only send the delete event.
199
+		time.Sleep(100 * time.Millisecond)
200
+
201
+		for i := 0; i < maxNumToCreate; i++ {
202
+			testFile := fmt.Sprintf("%s%d", testFilePrefix, i)
203
+			err = os.Remove(testFile)
204
+			if err != nil {
205
+				errChan <- fmt.Errorf("Remove failed: %v", err)
206
+			}
207
+		}
208
+
209
+		close(doneChan)
210
+	}()
211
+
212
+	creates := 0
213
+	removes := 0
214
+
215
+	finished := false
216
+	after := time.After(10 * time.Second)
217
+	for !finished {
218
+		select {
219
+		case <-after:
220
+			t.Fatalf("Not done")
221
+		case <-doneChan:
222
+			finished = true
223
+		case err := <-errChan:
224
+			t.Fatalf("Got an error from file creator goroutine: %v", err)
225
+		case err := <-w.Errors:
226
+			t.Fatalf("Got an error from watcher: %v", err)
227
+		case evt := <-w.Events:
228
+			if !strings.HasPrefix(evt.Name, testFilePrefix) {
229
+				t.Fatalf("Got an event for an unknown file: %s", evt.Name)
230
+			}
231
+			if evt.Op == Create {
232
+				creates++
233
+			}
234
+			if evt.Op == Remove {
235
+				removes++
236
+			}
237
+		}
238
+	}
239
+
240
+	// Drain remaining events from channels
241
+	count := 0
242
+	for count < 10 {
243
+		select {
244
+		case err := <-errChan:
245
+			t.Fatalf("Got an error from file creator goroutine: %v", err)
246
+		case err := <-w.Errors:
247
+			t.Fatalf("Got an error from watcher: %v", err)
248
+		case evt := <-w.Events:
249
+			if !strings.HasPrefix(evt.Name, testFilePrefix) {
250
+				t.Fatalf("Got an event for an unknown file: %s", evt.Name)
251
+			}
252
+			if evt.Op == Create {
253
+				creates++
254
+			}
255
+			if evt.Op == Remove {
256
+				removes++
257
+			}
258
+			count = 0
259
+		default:
260
+			count++
261
+			// Give the watcher chances to fill the channels.
262
+			time.Sleep(time.Millisecond)
263
+		}
264
+	}
265
+
266
+	if creates-removes > 1 || creates-removes < -1 {
267
+		t.Fatalf("Creates and removes should not be off by more than one: %d creates, %d removes", creates, removes)
268
+	}
269
+	if creates < 50 {
270
+		t.Fatalf("Expected at least 50 creates, got %d", creates)
271
+	}
272
+}
273
+
274
+func TestInotifyRemoveTwice(t *testing.T) {
275
+	testDir := tempMkdir(t)
276
+	defer os.RemoveAll(testDir)
277
+	testFile := filepath.Join(testDir, "testfile")
278
+
279
+	handle, err := os.Create(testFile)
280
+	if err != nil {
281
+		t.Fatalf("Create failed: %v", err)
282
+	}
283
+	handle.Close()
284
+
285
+	w, err := NewWatcher()
286
+	if err != nil {
287
+		t.Fatalf("Failed to create watcher: %v", err)
288
+	}
289
+	defer w.Close()
290
+
291
+	err = w.Add(testFile)
292
+	if err != nil {
293
+		t.Fatalf("Failed to add testFile: %v", err)
294
+	}
295
+
296
+	err = w.Remove(testFile)
297
+	if err != nil {
298
+		t.Fatalf("wanted successful remove but got:", err)
299
+	}
300
+
301
+	err = w.Remove(testFile)
302
+	if err == nil {
303
+		t.Fatalf("no error on removing invalid file")
304
+	}
305
+
306
+	w.mu.Lock()
307
+	defer w.mu.Unlock()
308
+	if len(w.watches) != 0 {
309
+		t.Fatalf("Expected watches len is 0, but got: %d, %v", len(w.watches), w.watches)
310
+	}
311
+	if len(w.paths) != 0 {
312
+		t.Fatalf("Expected paths len is 0, but got: %d, %v", len(w.paths), w.paths)
313
+	}
314
+}
315
+
316
+func TestInotifyInnerMapLength(t *testing.T) {
317
+	testDir := tempMkdir(t)
318
+	defer os.RemoveAll(testDir)
319
+	testFile := filepath.Join(testDir, "testfile")
320
+
321
+	handle, err := os.Create(testFile)
322
+	if err != nil {
323
+		t.Fatalf("Create failed: %v", err)
324
+	}
325
+	handle.Close()
326
+
327
+	w, err := NewWatcher()
328
+	if err != nil {
329
+		t.Fatalf("Failed to create watcher: %v", err)
330
+	}
331
+	defer w.Close()
332
+
333
+	err = w.Add(testFile)
334
+	if err != nil {
335
+		t.Fatalf("Failed to add testFile: %v", err)
336
+	}
337
+	go func() {
338
+		for err := range w.Errors {
339
+			t.Fatalf("error received: %s", err)
340
+		}
341
+	}()
342
+
343
+	err = os.Remove(testFile)
344
+	if err != nil {
345
+		t.Fatalf("Failed to remove testFile: %v", err)
346
+	}
347
+	_ = <-w.Events                      // consume Remove event
348
+	<-time.After(50 * time.Millisecond) // wait IN_IGNORE propagated
349
+
350
+	w.mu.Lock()
351
+	defer w.mu.Unlock()
352
+	if len(w.watches) != 0 {
353
+		t.Fatalf("Expected watches len is 0, but got: %d, %v", len(w.watches), w.watches)
354
+	}
355
+	if len(w.paths) != 0 {
356
+		t.Fatalf("Expected paths len is 0, but got: %d, %v", len(w.paths), w.paths)
357
+	}
358
+}
359
+
360
+func TestInotifyOverflow(t *testing.T) {
361
+	// We need to generate many more events than the
362
+	// fs.inotify.max_queued_events sysctl setting.
363
+	// We use multiple goroutines (one per directory)
364
+	// to speed up file creation.
365
+	numDirs := 128
366
+	numFiles := 1024
367
+
368
+	testDir := tempMkdir(t)
369
+	defer os.RemoveAll(testDir)
370
+
371
+	w, err := NewWatcher()
372
+	if err != nil {
373
+		t.Fatalf("Failed to create watcher: %v", err)
374
+	}
375
+	defer w.Close()
376
+
377
+	for dn := 0; dn < numDirs; dn++ {
378
+		testSubdir := fmt.Sprintf("%s/%d", testDir, dn)
379
+
380
+		err := os.Mkdir(testSubdir, 0777)
381
+		if err != nil {
382
+			t.Fatalf("Cannot create subdir: %v", err)
383
+		}
384
+
385
+		err = w.Add(testSubdir)
386
+		if err != nil {
387
+			t.Fatalf("Failed to add subdir: %v", err)
388
+		}
389
+	}
390
+
391
+	errChan := make(chan error, numDirs*numFiles)
392
+
393
+	for dn := 0; dn < numDirs; dn++ {
394
+		testSubdir := fmt.Sprintf("%s/%d", testDir, dn)
395
+
396
+		go func() {
397
+			for fn := 0; fn < numFiles; fn++ {
398
+				testFile := fmt.Sprintf("%s/%d", testSubdir, fn)
399
+
400
+				handle, err := os.Create(testFile)
401
+				if err != nil {
402
+					errChan <- fmt.Errorf("Create failed: %v", err)
403
+					continue
404
+				}
405
+
406
+				err = handle.Close()
407
+				if err != nil {
408
+					errChan <- fmt.Errorf("Close failed: %v", err)
409
+					continue
410
+				}
411
+			}
412
+		}()
413
+	}
414
+
415
+	creates := 0
416
+	overflows := 0
417
+
418
+	after := time.After(10 * time.Second)
419
+	for overflows == 0 && creates < numDirs*numFiles {
420
+		select {
421
+		case <-after:
422
+			t.Fatalf("Not done")
423
+		case err := <-errChan:
424
+			t.Fatalf("Got an error from file creator goroutine: %v", err)
425
+		case err := <-w.Errors:
426
+			if err == ErrEventOverflow {
427
+				overflows++
428
+			} else {
429
+				t.Fatalf("Got an error from watcher: %v", err)
430
+			}
431
+		case evt := <-w.Events:
432
+			if !strings.HasPrefix(evt.Name, testDir) {
433
+				t.Fatalf("Got an event for an unknown file: %s", evt.Name)
434
+			}
435
+			if evt.Op == Create {
436
+				creates++
437
+			}
438
+		}
439
+	}
440
+
441
+	if creates == numDirs*numFiles {
442
+		t.Fatalf("Could not trigger overflow")
443
+	}
444
+
445
+	if overflows == 0 {
446
+		t.Fatalf("No overflow and not enough creates (expected %d, got %d)",
447
+			numDirs*numFiles, creates)
448
+	}
449
+}

+ 147
- 0
vendor/github.com/fsnotify/fsnotify/integration_darwin_test.go View File

@@ -0,0 +1,147 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package fsnotify
6
+
7
+import (
8
+	"os"
9
+	"path/filepath"
10
+	"testing"
11
+	"time"
12
+
13
+	"golang.org/x/sys/unix"
14
+)
15
+
16
+// testExchangedataForWatcher tests the watcher with the exchangedata operation on macOS.
17
+//
18
+// This is widely used for atomic saves on macOS, e.g. TextMate and in Apple's NSDocument.
19
+//
20
+// See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/exchangedata.2.html
21
+// Also see: https://github.com/textmate/textmate/blob/cd016be29489eba5f3c09b7b70b06da134dda550/Frameworks/io/src/swap_file_data.cc#L20
22
+func testExchangedataForWatcher(t *testing.T, watchDir bool) {
23
+	// Create directory to watch
24
+	testDir1 := tempMkdir(t)
25
+
26
+	// For the intermediate file
27
+	testDir2 := tempMkdir(t)
28
+
29
+	defer os.RemoveAll(testDir1)
30
+	defer os.RemoveAll(testDir2)
31
+
32
+	resolvedFilename := "TestFsnotifyEvents.file"
33
+
34
+	// TextMate does:
35
+	//
36
+	// 1. exchangedata (intermediate, resolved)
37
+	// 2. unlink intermediate
38
+	//
39
+	// Let's try to simulate that:
40
+	resolved := filepath.Join(testDir1, resolvedFilename)
41
+	intermediate := filepath.Join(testDir2, resolvedFilename+"~")
42
+
43
+	// Make sure we create the file before we start watching
44
+	createAndSyncFile(t, resolved)
45
+
46
+	watcher := newWatcher(t)
47
+
48
+	// Test both variants in isolation
49
+	if watchDir {
50
+		addWatch(t, watcher, testDir1)
51
+	} else {
52
+		addWatch(t, watcher, resolved)
53
+	}
54
+
55
+	// Receive errors on the error channel on a separate goroutine
56
+	go func() {
57
+		for err := range watcher.Errors {
58
+			t.Fatalf("error received: %s", err)
59
+		}
60
+	}()
61
+
62
+	// Receive events on the event channel on a separate goroutine
63
+	eventstream := watcher.Events
64
+	var removeReceived counter
65
+	var createReceived counter
66
+
67
+	done := make(chan bool)
68
+
69
+	go func() {
70
+		for event := range eventstream {
71
+			// Only count relevant events
72
+			if event.Name == filepath.Clean(resolved) {
73
+				if event.Op&Remove == Remove {
74
+					removeReceived.increment()
75
+				}
76
+				if event.Op&Create == Create {
77
+					createReceived.increment()
78
+				}
79
+			}
80
+			t.Logf("event received: %s", event)
81
+		}
82
+		done <- true
83
+	}()
84
+
85
+	// Repeat to make sure the watched file/directory "survives" the REMOVE/CREATE loop.
86
+	for i := 1; i <= 3; i++ {
87
+		// The intermediate file is created in a folder outside the watcher
88
+		createAndSyncFile(t, intermediate)
89
+
90
+		// 1. Swap
91
+		if err := unix.Exchangedata(intermediate, resolved, 0); err != nil {
92
+			t.Fatalf("[%d] exchangedata failed: %s", i, err)
93
+		}
94
+
95
+		time.Sleep(50 * time.Millisecond)
96
+
97
+		// 2. Delete the intermediate file
98
+		err := os.Remove(intermediate)
99
+
100
+		if err != nil {
101
+			t.Fatalf("[%d] remove %s failed: %s", i, intermediate, err)
102
+		}
103
+
104
+		time.Sleep(50 * time.Millisecond)
105
+
106
+	}
107
+
108
+	// We expect this event to be received almost immediately, but let's wait 500 ms to be sure
109
+	time.Sleep(500 * time.Millisecond)
110
+
111
+	// The events will be (CHMOD + REMOVE + CREATE) X 2. Let's focus on the last two:
112
+	if removeReceived.value() < 3 {
113
+		t.Fatal("fsnotify remove events have not been received after 500 ms")
114
+	}
115
+
116
+	if createReceived.value() < 3 {
117
+		t.Fatal("fsnotify create events have not been received after 500 ms")
118
+	}
119
+
120
+	watcher.Close()
121
+	t.Log("waiting for the event channel to become closed...")
122
+	select {
123
+	case <-done:
124
+		t.Log("event channel closed")
125
+	case <-time.After(2 * time.Second):
126
+		t.Fatal("event stream was not closed after 2 seconds")
127
+	}
128
+}
129
+
130
+// TestExchangedataInWatchedDir test exchangedata operation on file in watched dir.
131
+func TestExchangedataInWatchedDir(t *testing.T) {
132
+	testExchangedataForWatcher(t, true)
133
+}
134
+
135
+// TestExchangedataInWatchedDir test exchangedata operation on watched file.
136
+func TestExchangedataInWatchedFile(t *testing.T) {
137
+	testExchangedataForWatcher(t, false)
138
+}
139
+
140
+func createAndSyncFile(t *testing.T, filepath string) {
141
+	f1, err := os.OpenFile(filepath, os.O_WRONLY|os.O_CREATE, 0666)
142
+	if err != nil {
143
+		t.Fatalf("creating %s failed: %s", filepath, err)
144
+	}
145
+	f1.Sync()
146
+	f1.Close()
147
+}

+ 1237
- 0
vendor/github.com/fsnotify/fsnotify/integration_test.go
File diff suppressed because it is too large
View File


+ 503
- 0
vendor/github.com/fsnotify/fsnotify/kqueue.go View File

@@ -0,0 +1,503 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build freebsd openbsd netbsd dragonfly darwin
6
+
7
+package fsnotify
8
+
9
+import (
10
+	"errors"
11
+	"fmt"
12
+	"io/ioutil"
13
+	"os"
14
+	"path/filepath"
15
+	"sync"
16
+	"time"
17
+
18
+	"golang.org/x/sys/unix"
19
+)
20
+
21
+// Watcher watches a set of files, delivering events to a channel.
22
+type Watcher struct {
23
+	Events chan Event
24
+	Errors chan error
25
+	done   chan bool // Channel for sending a "quit message" to the reader goroutine
26
+
27
+	kq int // File descriptor (as returned by the kqueue() syscall).
28
+
29
+	mu              sync.Mutex        // Protects access to watcher data
30
+	watches         map[string]int    // Map of watched file descriptors (key: path).
31
+	externalWatches map[string]bool   // Map of watches added by user of the library.
32
+	dirFlags        map[string]uint32 // Map of watched directories to fflags used in kqueue.
33
+	paths           map[int]pathInfo  // Map file descriptors to path names for processing kqueue events.
34
+	fileExists      map[string]bool   // Keep track of if we know this file exists (to stop duplicate create events).
35
+	isClosed        bool              // Set to true when Close() is first called
36
+}
37
+
38
+type pathInfo struct {
39
+	name  string
40
+	isDir bool
41
+}
42
+
43
+// NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
44
+func NewWatcher() (*Watcher, error) {
45
+	kq, err := kqueue()
46
+	if err != nil {
47
+		return nil, err
48
+	}
49
+
50
+	w := &Watcher{
51
+		kq:              kq,
52
+		watches:         make(map[string]int),
53
+		dirFlags:        make(map[string]uint32),
54
+		paths:           make(map[int]pathInfo),
55
+		fileExists:      make(map[string]bool),
56
+		externalWatches: make(map[string]bool),
57
+		Events:          make(chan Event),
58
+		Errors:          make(chan error),
59
+		done:            make(chan bool),
60
+	}
61
+
62
+	go w.readEvents()
63
+	return w, nil
64
+}
65
+
66
+// Close removes all watches and closes the events channel.
67
+func (w *Watcher) Close() error {
68
+	w.mu.Lock()
69
+	if w.isClosed {
70
+		w.mu.Unlock()
71
+		return nil
72
+	}
73
+	w.isClosed = true
74
+	w.mu.Unlock()
75
+
76
+	// copy paths to remove while locked
77
+	w.mu.Lock()
78
+	var pathsToRemove = make([]string, 0, len(w.watches))
79
+	for name := range w.watches {
80
+		pathsToRemove = append(pathsToRemove, name)
81
+	}
82
+	w.mu.Unlock()
83
+	// unlock before calling Remove, which also locks
84
+
85
+	var err error
86
+	for _, name := range pathsToRemove {
87
+		if e := w.Remove(name); e != nil && err == nil {
88
+			err = e
89
+		}
90
+	}
91
+
92
+	// Send "quit" message to the reader goroutine:
93
+	w.done <- true
94
+
95
+	return nil
96
+}
97
+
98
+// Add starts watching the named file or directory (non-recursively).
99
+func (w *Watcher) Add(name string) error {
100
+	w.mu.Lock()
101
+	w.externalWatches[name] = true
102
+	w.mu.Unlock()
103
+	_, err := w.addWatch(name, noteAllEvents)
104
+	return err
105
+}
106
+
107
+// Remove stops watching the the named file or directory (non-recursively).
108
+func (w *Watcher) Remove(name string) error {
109
+	name = filepath.Clean(name)
110
+	w.mu.Lock()
111
+	watchfd, ok := w.watches[name]
112
+	w.mu.Unlock()
113
+	if !ok {
114
+		return fmt.Errorf("can't remove non-existent kevent watch for: %s", name)
115
+	}
116
+
117
+	const registerRemove = unix.EV_DELETE
118
+	if err := register(w.kq, []int{watchfd}, registerRemove, 0); err != nil {
119
+		return err
120
+	}
121
+
122
+	unix.Close(watchfd)
123
+
124
+	w.mu.Lock()
125
+	isDir := w.paths[watchfd].isDir
126
+	delete(w.watches, name)
127
+	delete(w.paths, watchfd)
128
+	delete(w.dirFlags, name)
129
+	w.mu.Unlock()
130
+
131
+	// Find all watched paths that are in this directory that are not external.
132
+	if isDir {
133
+		var pathsToRemove []string
134
+		w.mu.Lock()
135
+		for _, path := range w.paths {
136
+			wdir, _ := filepath.Split(path.name)
137
+			if filepath.Clean(wdir) == name {
138
+				if !w.externalWatches[path.name] {
139
+					pathsToRemove = append(pathsToRemove, path.name)
140
+				}
141
+			}
142
+		}
143
+		w.mu.Unlock()
144
+		for _, name := range pathsToRemove {
145
+			// Since these are internal, not much sense in propagating error
146
+			// to the user, as that will just confuse them with an error about
147
+			// a path they did not explicitly watch themselves.
148
+			w.Remove(name)
149
+		}
150
+	}
151
+
152
+	return nil
153
+}
154
+
155
+// Watch all events (except NOTE_EXTEND, NOTE_LINK, NOTE_REVOKE)
156
+const noteAllEvents = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_ATTRIB | unix.NOTE_RENAME
157
+
158
+// keventWaitTime to block on each read from kevent
159
+var keventWaitTime = durationToTimespec(100 * time.Millisecond)
160
+
161
+// addWatch adds name to the watched file set.
162
+// The flags are interpreted as described in kevent(2).
163
+// Returns the real path to the file which was added, if any, which may be different from the one passed in the case of symlinks.
164
+func (w *Watcher) addWatch(name string, flags uint32) (string, error) {
165
+	var isDir bool
166
+	// Make ./name and name equivalent
167
+	name = filepath.Clean(name)
168
+
169
+	w.mu.Lock()
170
+	if w.isClosed {
171
+		w.mu.Unlock()
172
+		return "", errors.New("kevent instance already closed")
173
+	}
174
+	watchfd, alreadyWatching := w.watches[name]
175
+	// We already have a watch, but we can still override flags.
176
+	if alreadyWatching {
177
+		isDir = w.paths[watchfd].isDir
178
+	}
179
+	w.mu.Unlock()
180
+
181
+	if !alreadyWatching {
182
+		fi, err := os.Lstat(name)
183
+		if err != nil {
184
+			return "", err
185
+		}
186
+
187
+		// Don't watch sockets.
188
+		if fi.Mode()&os.ModeSocket == os.ModeSocket {
189
+			return "", nil
190
+		}
191
+
192
+		// Don't watch named pipes.
193
+		if fi.Mode()&os.ModeNamedPipe == os.ModeNamedPipe {
194
+			return "", nil
195
+		}
196
+
197
+		// Follow Symlinks
198
+		// Unfortunately, Linux can add bogus symlinks to watch list without
199
+		// issue, and Windows can't do symlinks period (AFAIK). To  maintain
200
+		// consistency, we will act like everything is fine. There will simply
201
+		// be no file events for broken symlinks.
202
+		// Hence the returns of nil on errors.
203
+		if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
204
+			name, err = filepath.EvalSymlinks(name)
205
+			if err != nil {
206
+				return "", nil
207
+			}
208
+
209
+			w.mu.Lock()
210
+			_, alreadyWatching = w.watches[name]
211
+			w.mu.Unlock()
212
+
213
+			if alreadyWatching {
214
+				return name, nil
215
+			}
216
+
217
+			fi, err = os.Lstat(name)
218
+			if err != nil {
219
+				return "", nil
220
+			}
221
+		}
222
+
223
+		watchfd, err = unix.Open(name, openMode, 0700)
224
+		if watchfd == -1 {
225
+			return "", err
226
+		}
227
+
228
+		isDir = fi.IsDir()
229
+	}
230
+
231
+	const registerAdd = unix.EV_ADD | unix.EV_CLEAR | unix.EV_ENABLE
232
+	if err := register(w.kq, []int{watchfd}, registerAdd, flags); err != nil {
233
+		unix.Close(watchfd)
234
+		return "", err
235
+	}
236
+
237
+	if !alreadyWatching {
238
+		w.mu.Lock()
239
+		w.watches[name] = watchfd
240
+		w.paths[watchfd] = pathInfo{name: name, isDir: isDir}
241
+		w.mu.Unlock()
242
+	}
243
+
244
+	if isDir {
245
+		// Watch the directory if it has not been watched before,
246
+		// or if it was watched before, but perhaps only a NOTE_DELETE (watchDirectoryFiles)
247
+		w.mu.Lock()
248
+
249
+		watchDir := (flags&unix.NOTE_WRITE) == unix.NOTE_WRITE &&
250
+			(!alreadyWatching || (w.dirFlags[name]&unix.NOTE_WRITE) != unix.NOTE_WRITE)
251
+		// Store flags so this watch can be updated later
252
+		w.dirFlags[name] = flags
253
+		w.mu.Unlock()
254
+
255
+		if watchDir {
256
+			if err := w.watchDirectoryFiles(name); err != nil {
257
+				return "", err
258
+			}
259
+		}
260
+	}
261
+	return name, nil
262
+}
263
+
264
+// readEvents reads from kqueue and converts the received kevents into
265
+// Event values that it sends down the Events channel.
266
+func (w *Watcher) readEvents() {
267
+	eventBuffer := make([]unix.Kevent_t, 10)
268
+
269
+	for {
270
+		// See if there is a message on the "done" channel
271
+		select {
272
+		case <-w.done:
273
+			err := unix.Close(w.kq)
274
+			if err != nil {
275
+				w.Errors <- err
276
+			}
277
+			close(w.Events)
278
+			close(w.Errors)
279
+			return
280
+		default:
281
+		}
282
+
283
+		// Get new events
284
+		kevents, err := read(w.kq, eventBuffer, &keventWaitTime)
285
+		// EINTR is okay, the syscall was interrupted before timeout expired.
286
+		if err != nil && err != unix.EINTR {
287
+			w.Errors <- err
288
+			continue
289
+		}
290
+
291
+		// Flush the events we received to the Events channel
292
+		for len(kevents) > 0 {
293
+			kevent := &kevents[0]
294
+			watchfd := int(kevent.Ident)
295
+			mask := uint32(kevent.Fflags)
296
+			w.mu.Lock()
297
+			path := w.paths[watchfd]
298
+			w.mu.Unlock()
299
+			event := newEvent(path.name, mask)
300
+
301
+			if path.isDir && !(event.Op&Remove == Remove) {
302
+				// Double check to make sure the directory exists. This can happen when
303
+				// we do a rm -fr on a recursively watched folders and we receive a
304
+				// modification event first but the folder has been deleted and later
305
+				// receive the delete event
306
+				if _, err := os.Lstat(event.Name); os.IsNotExist(err) {
307
+					// mark is as delete event
308
+					event.Op |= Remove
309
+				}
310
+			}
311
+
312
+			if event.Op&Rename == Rename || event.Op&Remove == Remove {
313
+				w.Remove(event.Name)
314
+				w.mu.Lock()
315
+				delete(w.fileExists, event.Name)
316
+				w.mu.Unlock()
317
+			}
318
+
319
+			if path.isDir && event.Op&Write == Write && !(event.Op&Remove == Remove) {
320
+				w.sendDirectoryChangeEvents(event.Name)
321
+			} else {
322
+				// Send the event on the