From 34e063c2fa1e11377ee762a6b3efef27ee3500a0 Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Tue, 3 Jul 2012 06:06:23 -0700 Subject: [PATCH] Linux - Added file name back to event path --- fsnotify_linux.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fsnotify_linux.go b/fsnotify_linux.go index f640dcc..a0d10b9 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -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 -- 2.50.1