equal
deleted
inserted
replaced
1 // Copyright 2010 The Go Authors. All rights reserved. |
1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style |
2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. |
3 // license that can be found in the LICENSE file. |
4 |
4 |
|
5 //go:build linux |
5 // +build linux |
6 // +build linux |
6 |
7 |
7 package fsnotify |
8 package fsnotify |
8 |
9 |
9 import ( |
10 import ( |
160 } |
161 } |
161 |
162 |
162 return nil |
163 return nil |
163 } |
164 } |
164 |
165 |
|
166 // WatchList returns the directories and files that are being monitered. |
|
167 func (w *Watcher) WatchList() []string { |
|
168 w.mu.Lock() |
|
169 defer w.mu.Unlock() |
|
170 |
|
171 entries := make([]string, 0, len(w.watches)) |
|
172 for pathname := range w.watches { |
|
173 entries = append(entries, pathname) |
|
174 } |
|
175 |
|
176 return entries |
|
177 } |
|
178 |
165 type watch struct { |
179 type watch struct { |
166 wd uint32 // Watch descriptor (as returned by the inotify_add_watch() syscall) |
180 wd uint32 // Watch descriptor (as returned by the inotify_add_watch() syscall) |
167 flags uint32 // inotify flags of this watch (see inotify(7) for the list of valid flags) |
181 flags uint32 // inotify flags of this watch (see inotify(7) for the list of valid flags) |
168 } |
182 } |
169 |
183 |
270 } |
284 } |
271 w.mu.Unlock() |
285 w.mu.Unlock() |
272 |
286 |
273 if nameLen > 0 { |
287 if nameLen > 0 { |
274 // Point "bytes" at the first byte of the filename |
288 // Point "bytes" at the first byte of the filename |
275 bytes := (*[unix.PathMax]byte)(unsafe.Pointer(&buf[offset+unix.SizeofInotifyEvent])) |
289 bytes := (*[unix.PathMax]byte)(unsafe.Pointer(&buf[offset+unix.SizeofInotifyEvent]))[:nameLen:nameLen] |
276 // The filename is padded with NULL bytes. TrimRight() gets rid of those. |
290 // The filename is padded with NULL bytes. TrimRight() gets rid of those. |
277 name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000") |
291 name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000") |
278 } |
292 } |
279 |
293 |
280 event := newEvent(name, mask) |
294 event := newEvent(name, mask) |