Repos / s4g / d2ca0d6d3e
commit d2ca0d6d3e3212b710073c49c122dc7ba35b7921
Author: Nhân <hi@imnhan.com>
Date: Wed Aug 30 17:44:46 2023 +0700
better infinite loop workaround
diff --git a/watcher.go b/watcher.go
index 4f3d8bd..cf90dfd 100644
--- a/watcher.go
+++ b/watcher.go
@@ -12,8 +12,6 @@
"go.imnhan.com/s4g/writablefs"
)
-var WatchedExts = []string{DjotExt, ".tmpl", ".txt"}
-
const debounceInterval = 500 * time.Millisecond
// Watches for relevant changes in FS, debounces by debounceInterval,
@@ -54,22 +52,24 @@ func WatchLocalFS(fsys writablefs.FS, callback func()) (Close func() error) {
return
}
- //relPath, err := filepath.Rel(fsysPath, event.Name)
- //if err != nil {
- //panic(err)
- //}
- //fmt.Println("EVENT:", event.Op, relPath)
-
if shouldIgnore(event.Name) {
break
}
+ relPath, err := filepath.Rel(fsysPath, event.Name)
+ if err != nil {
+ panic(err)
+ }
+
// Avoid infinite loop
- if event.Has(fsnotify.Write) &&
- !contains(WatchedExts, filepath.Ext(event.Name)) {
+ if filepath.Ext(relPath) == ".html" ||
+ relPath == FeedPath ||
+ relPath == ManifestPath {
break
}
+ //fmt.Println("EVENT:", event.Op, relPath)
+
// Dynamically watch new/renamed folders
if event.Has(fsnotify.Create) || event.Has(fsnotify.Rename) {
stat, err := os.Stat(event.Name)