Revert "watch: fix inotify tests on windows" (#3147)

This reverts commit 74ac7997b1c8f497babbbd499ff1f047563d699a.
This commit is contained in:
Nick Santos 2020-03-30 13:24:49 -04:00 committed by Nicolas De loof
parent dda0362b6e
commit d2d4d05264
3 changed files with 6 additions and 47 deletions

View File

@ -1,3 +1,5 @@
// +build !windows
package watch
import (
@ -39,9 +41,6 @@ func TestNoWatches(t *testing.T) {
}
func TestEventOrdering(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on windows for now")
}
f := newNotifyFixture(t)
defer f.tearDown()
@ -74,9 +73,6 @@ func TestEventOrdering(t *testing.T) {
// of directories, creates files in them, then deletes
// them all quickly. Make sure there are no errors.
func TestGitBranchSwitch(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on windows for now")
}
f := newNotifyFixture(t)
defer f.tearDown()
@ -147,11 +143,10 @@ func TestWatchesAreRecursive(t *testing.T) {
f.events = nil
// change sub directory
changeFilePath := filepath.Join(subPath, "change")
h, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
_, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
if err != nil {
t.Fatal(err)
}
defer h.Close()
f.assertEvents(changeFilePath)
}
@ -173,12 +168,10 @@ func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
// change something inside sub directory
changeFilePath := filepath.Join(subPath, "change")
h, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
_, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
if err != nil {
t.Fatal(err)
}
defer h.Close()
f.assertEvents(subPath, changeFilePath)
}
@ -285,9 +278,6 @@ func TestSingleFile(t *testing.T) {
}
func TestWriteBrokenLink(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Symlink creation requires admin privileges on Windows")
}
f := newNotifyFixture(t)
defer f.tearDown()
@ -302,9 +292,6 @@ func TestWriteBrokenLink(t *testing.T) {
}
func TestWriteGoodLink(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Symlink creation requires admin privileges on Windows")
}
f := newNotifyFixture(t)
defer f.tearDown()
@ -324,9 +311,6 @@ func TestWriteGoodLink(t *testing.T) {
}
func TestWatchBrokenLink(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Symlink creation requires admin privileges on Windows")
}
f := newNotifyFixture(t)
defer f.tearDown()
@ -355,10 +339,6 @@ func TestWatchBrokenLink(t *testing.T) {
}
func TestMoveAndReplace(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on windows for now")
}
f := newNotifyFixture(t)
defer f.tearDown()

View File

@ -6,7 +6,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/pkg/errors"
"github.com/windmilleng/fsnotify"
@ -136,7 +135,7 @@ func (d *naiveNotify) loop() {
defer close(d.wrappedEvents)
for e := range d.events {
if e.Op&fsnotify.Create != fsnotify.Create {
if d.shouldNotify(e.Name) && !isSpuriousWindowsDirChange(e) {
if d.shouldNotify(e.Name) {
d.wrappedEvents <- FileEvent{e.Name}
}
continue
@ -263,22 +262,6 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti
return wmw, nil
}
// Windows' inotify implementation sometimes fires
// of spurious WRITE events on directories when the
// files inside change.
func isSpuriousWindowsDirChange(e fsnotify.Event) bool {
if runtime.GOOS != "windows" {
return false
}
if e.Op != fsnotify.Write {
return false
}
eIsDir, _ := isDir(e.Name)
return eIsDir
}
func isDir(pth string) (bool, error) {
fi, err := os.Lstat(pth)
if os.IsNotExist(err) {

View File

@ -1,4 +1,4 @@
// +build !darwin
// +build !darwin,!windows
package watch
@ -6,7 +6,6 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"testing"
@ -93,9 +92,6 @@ func TestDontWatchEachFile(t *testing.T) {
f.events = nil
pid := os.Getpid()
if runtime.GOOS == "windows" {
return // skip the inotify count
}
output, err := exec.Command("bash", "-c", fmt.Sprintf(
"find /proc/%d/fd -lname anon_inode:inotify -printf '%%hinfo/%%f\n' | xargs cat | grep -c '^inotify'", pid)).Output()