]> go.fuhry.dev Git - fsnotify.git/commitdiff
Linux - Added file name back to event path
authorChris Howey <chris@howey.me>
Tue, 3 Jul 2012 13:06:23 +0000 (06:06 -0700)
committerChris Howey <chris@howey.me>
Tue, 3 Jul 2012 13:06:23 +0000 (06:06 -0700)
fsnotify_linux.go

index f640dcc0d3423a5955ee86af76936a104bb1ee6b..a0d10b99ffe455253048ef67e323c75aeda5215f 100644 (file)
@@ -11,6 +11,7 @@ import (
        "errors"
        "fmt"
        "os"
+       "strings"
        "syscall"
        "unsafe"
 )
@@ -189,6 +190,21 @@ func (w *Watcher) readEvents() {
                        // the "Name" field with a valid filename. We retrieve the path of the watch from
                        // the "paths" map.
                        event.Name = w.paths[int(raw.Wd)]
+                       watchedName := event.Name
+                       if nameLen > 0 {
+                               // Point "bytes" at the first byte of the filename
+                               bytes := (*[syscall.PathMax]byte)(unsafe.Pointer(&buf[offset+syscall.SizeofInotifyEvent]))
+                               // The filename is padded with NUL bytes. TrimRight() gets rid of those.
+                               event.Name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000")
+                       }
+
+                       // Setup FSNotify flags (inherit from directory watch)
+                       fsnFlags := w.fsnFlags[watchedName]
+                       _, fsnFound := w.fsnFlags[event.Name]
+                       if !fsnFound {
+                               w.fsnFlags[event.Name] = fsnFlags
+                       }
+
                        // Send the events that are not ignored on the events channel
                        if (event.mask & IN_IGNORED) == 0 {
                                w.internalEvent <- event