]> go.fuhry.dev Git - fsnotify.git/commitdiff
code review from Ian Lance Taylor
authorNathan Youngman <git@nathany.com>
Thu, 6 Feb 2014 03:06:35 +0000 (20:06 -0700)
committerNathan Youngman <git@nathany.com>
Thu, 6 Feb 2014 03:06:35 +0000 (20:06 -0700)
fsnotify_bsd.go
fsnotify_linux.go
fsnotify_windows.go

index 85aeeb3200197767c87a9ec6dabb05cbf538c8ca..7fb24af80d9868c43d813122c042730ba39fa043 100644 (file)
@@ -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)
                }
        }
 
index acb6fe05202d9c2eaa8f6a6e10d885264d5f313d..80ade879fde01cd09a0be1674c29e975b749143b 100644 (file)
@@ -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 {
index 02b4f1fb10308bb9f4863518706b0b332fcc9915..d88ae63407d2316be0c7247ddae19a41c9bbbce9 100644 (file)
@@ -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: