Debian Codegraph @

watch.go

raw symbols SCIP
1 package mainscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/
2
3 import (
4 "osscip-go gomod github.com/golang/go/src go1.24.0 os/"
5 "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/"
6 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
7
8 "github.com/fsnotify/fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/"
9 )
10
11 const chmodMaskscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/chmodMask. fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/.Opscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Op# = ^fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/.Opscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Op#(0) ^ fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/.Chmodscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Chmod.
12
13 // watch recursively watches changes in root and reports the filenames to names.
14 // It sends an error on the done chan.
15 // As an optimization, any dirs we encounter that meet the ExcludePrefix
16 // criteria of all reflexes can be ignored.
17 func watchscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/watch().(root string, watcher *fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/.Watcherscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Watcher#, names chan<- string, done chan<- error, reflexes []*Reflexscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/Reflex#) {
18 if err := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Walkscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Walk().(root, walkerscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/walker().(watcher, reflexes)); err != nil {
19 infoPrintfscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/infoPrintf().(-1, "Error while walking path %s: %s", root, err)
20 }
21
22 for {
23 select {
24 case e := <-watcher.Eventsscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Watcher#Events.:
25 if verbosescip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/verbose. {
26 infoPrintlnscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/infoPrintln().(-1, "fsnotify event:", e)
27 }
28 stat, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Statscip-go gomod github.com/golang/go/src go1.24.0 os/Stat().(e.Namescip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Event#Name.)
29 if err != nil {
30 continue
31 }
32 path := normalizescip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/normalize().(e.Namescip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Event#Name., stat.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().())
33 if e.Opscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Event#Op.&chmodMaskscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/chmodMask. == 0 {
34 continue
35 }
36 names <- path
37 if e.Opscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Event#Op.&fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/.Createscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Create. > 0 && stat.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().() {
38 if err := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Walkscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Walk().(path, walkerscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/walker().(watcher, reflexes)); err != nil {
39 infoPrintfscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/infoPrintf().(-1, "Error while walking path %s: %s", path, err)
40 }
41 }
42 // TODO: Cannot currently remove fsnotify watches
43 // recursively, or for deleted files. See:
44 // https://github.com/cespare/reflex/issues/13
45 // https://github.com/go-fsnotify/fsnotify/issues/40
46 // https://github.com/go-fsnotify/fsnotify/issues/41
47 case err := <-watcher.Errorsscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Watcher#Errors.:
48 done <- err
49 return
50 }
51 }
52 }
53
54 func walkerscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/walker().(watcher *fsnotifyscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/.Watcherscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Watcher#, reflexes []*Reflexscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/Reflex#) filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.WalkFuncscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/WalkFunc# {
55 return func(path string, f osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.24.0 os/FileInfo#, err error) error {
56 if err != nil || !f.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().() {
57 return nil
58 }
59 path = normalizescip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/normalize().(path, f.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().())
60 ignore := true
61 for _, r := range reflexes {
62 if !r.matcherscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/Reflex#matcher..ExcludePrefixscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/Matcher#ExcludePrefix.(path) {
63 ignore = false
64 break
65 }
66 }
67 if ignore {
68 return filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.SkipDirscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/SkipDir.
69 }
70 if err := watcher.Addscip-go gomod github.com/fsnotify/fsnotify v1.9.0 `github.com/fsnotify/fsnotify`/Watcher#Add().(path); err != nil {
71 infoPrintfscip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/infoPrintf().(-1, "Error while watching new path %s: %s", path, err)
72 }
73 return nil
74 }
75 }
76
77 func normalizescip-go gomod github.com/cespare/reflex . `github.com/cespare/reflex`/normalize().(path string, dir bool) string {
78 path = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/TrimPrefix().(path, "./")
79 if dir && !stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasSuffix().(path, "/") {
80 path = path + "/"
81 }
82 return path
83 }