MCPcopy Index your code
hub / github.com/tdewolff/minify / AddPath

Method AddPath

cmd/minify/watch.go:48–84  ·  view source on GitHub ↗

AddPath adds a new path to watch.

(path string)

Source from the content-addressed store, hash-verified

46
47// AddPath adds a new path to watch.
48func (w *Watcher) AddPath(path string) error {
49 path = filepath.Clean(path)
50 w.paths[path] = true
51
52 info, err := os.Lstat(path)
53 if err != nil {
54 return err
55 }
56
57 if info.Mode().IsRegular() {
58 root := filepath.Dir(path)
59 if w.dirs[root] {
60 return nil
61 }
62 if err := w.watcher.Add(root); err != nil {
63 return err
64 }
65 w.dirs[root] = true
66 } else if info.Mode().IsDir() && w.recursive {
67 return fs.WalkDir(os.DirFS("."), path, func(path string, d fs.DirEntry, err error) error {
68 if err != nil {
69 return err
70 }
71 if d.IsDir() {
72 if w.dirs[path] {
73 return fs.SkipDir
74 }
75 if err := w.watcher.Add(path); err != nil {
76 return err
77 }
78 w.dirs[path] = true
79 }
80 return nil
81 })
82 }
83 return nil
84}
85
86// Run watches for file changes.
87func (w *Watcher) Run() chan string {

Callers 2

RunMethod · 0.95
runFunction · 0.95

Calls 1

AddMethod · 0.80

Tested by

no test coverage detected