From 0713b5aac38d7efb40d039267bbc5f1c3c65990c Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Wed, 5 Feb 2014 20:06:35 -0700 Subject: [PATCH] code review from Ian Lance Taylor --- fsnotify_bsd.go | 11 +++++------ fsnotify_linux.go | 5 ++--- fsnotify_windows.go | 11 +++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index 85aeeb3..7fb24af 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -53,8 +53,7 @@ func (e *FileEvent) IsModify() bool { // IsRename reports whether the FileEvent was triggered by a change name func (e *FileEvent) IsRename() bool { return (e.mask & sys_NOTE_RENAME) == sys_NOTE_RENAME } -// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata (eg. -// atime, mtime etc.) +// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata. func (e *FileEvent) IsAttrib() bool { return (e.mask & sys_NOTE_ATTRIB) == sys_NOTE_ATTRIB } @@ -272,24 +271,24 @@ func (w *Watcher) removeWatch(path string) error { // Find all watched paths that are in this directory that are not external. if fInfo.IsDir() { - pathsToRemove := make([]string, 0) + var pathsToRemove []string w.pmut.Lock() for _, wpath := range w.paths { wdir, _ := filepath.Split(wpath) if filepath.Clean(wdir) == filepath.Clean(path) { w.ewmut.Lock() - if _, extern := w.externalWatches[wpath]; !extern { + if !w.externalWatches[wpath] { pathsToRemove = append(pathsToRemove, wpath) } w.ewmut.Unlock() } } w.pmut.Unlock() - for idx := 0; idx < len(pathsToRemove); idx++ { + for _, p := range pathsToRemove { // Since these are internal, not much sense in propagating error // to the user, as that will just confuse them with an error about // a path they did not explicitly watch themselves. - w.removeWatch(pathsToRemove[idx]) + w.removeWatch(p) } } diff --git a/fsnotify_linux.go b/fsnotify_linux.go index acb6fe0..80ade87 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -82,8 +82,7 @@ func (e *FileEvent) IsRename() bool { return ((e.mask&sys_IN_MOVE_SELF) == sys_IN_MOVE_SELF || (e.mask&sys_IN_MOVED_FROM) == sys_IN_MOVED_FROM) } -// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata (eg. -// atime, mtime etc.) +// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata. func (e *FileEvent) IsAttrib() bool { return (e.mask & sys_IN_ATTRIB) == sys_IN_ATTRIB } @@ -217,7 +216,7 @@ func (w *Watcher) readEvents() { default: } - n, errno = syscall.Read(w.fd, buf[0:]) + n, errno = syscall.Read(w.fd, buf[:]) // If EOF is received if n == 0 { diff --git a/fsnotify_windows.go b/fsnotify_windows.go index 02b4f1f..d88ae63 100644 --- a/fsnotify_windows.go +++ b/fsnotify_windows.go @@ -72,8 +72,7 @@ func (e *FileEvent) IsRename() bool { return ((e.mask&sys_FS_MOVE) == sys_FS_MOVE || (e.mask&sys_FS_MOVE_SELF) == sys_FS_MOVE_SELF || (e.mask&sys_FS_MOVED_FROM) == sys_FS_MOVED_FROM || (e.mask&sys_FS_MOVED_TO) == sys_FS_MOVED_TO) } -// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata (eg. -// atime, mtime etc.) +// IsAttrib reports whether the FileEvent was triggered by a change in the file metadata. func (e *FileEvent) IsAttrib() bool { return (e.mask & sys_FS_ATTRIB) == sys_FS_ATTRIB } @@ -417,7 +416,7 @@ func (w *Watcher) readEvents() { select { case ch := <-w.quit: w.mu.Lock() - indexes := make([]indexMap, 0) + var indexes []indexMap for _, index := range w.watches { indexes = append(indexes, index) } @@ -453,9 +452,9 @@ func (w *Watcher) readEvents() { if watch == nil { w.Error <- errors.New("ERROR_MORE_DATA has unexpectedly null lpOverlapped buffer") } else { - //The i/o succeeded but buffer is full - //in theory we should be building up a full packet - //in practice we can get away with just carrying on + // The i/o succeeded but the buffer is full. + // In theory we should be building up a full packet. + // In practice we can get away with just carrying on. n = uint32(unsafe.Sizeof(watch.buf)) } case syscall.ERROR_ACCESS_DENIED: -- 2.50.1