aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/watchfs/filestate.go16
-rw-r--r--lib/watchfs/nodestate.go12
-rw-r--r--lib/watchfs/watchcallback.go9
-rw-r--r--lib/watchfs/watcher.go9
-rw-r--r--lib/watchfs/watchfs.go21
5 files changed, 34 insertions, 33 deletions
diff --git a/lib/watchfs/filestate.go b/lib/watchfs/filestate.go
index 18c3676c..c485665c 100644
--- a/lib/watchfs/filestate.go
+++ b/lib/watchfs/filestate.go
@@ -4,15 +4,19 @@
package watchfs
// FileState define the state of file.
-// There are four states of file: created, updated on mode, updated on content
-// or deleted.
+// There are four states of file: created, updated on mode, updated on
+// content or deleted.
type FileState byte
const (
- FileStateCreated FileState = iota // FileStateCreated when new file is created.
- FileStateUpdateContent // FileStateUpdateContent when the content of file is modified.
- FileStateUpdateMode // FileStateUpdateMode when the mode of file is modified.
- FileStateDeleted // FileStateDeleted when the file has been deleted.
+ // FileStateCreated when new file is created.
+ FileStateCreated FileState = iota
+ // FileStateUpdateContent when the content of file is modified.
+ FileStateUpdateContent
+ // FileStateUpdateMode when the mode of file is modified.
+ FileStateUpdateMode
+ // FileStateDeleted when the file has been deleted.
+ FileStateDeleted
)
// String return the string representation of FileState.
diff --git a/lib/watchfs/nodestate.go b/lib/watchfs/nodestate.go
deleted file mode 100644
index 339dac40..00000000
--- a/lib/watchfs/nodestate.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// SPDX-FileCopyrightText: 2019 M. Shulhan <ms@kilabit.info>
-// SPDX-License-Identifier: BSD-3-Clause
-
-package watchfs
-
-// NodeState contains the information about the file and its state.
-type NodeState struct {
- // Node represent the file information.
- Node Node
- // State of file, its either created, modified, or deleted.
- State FileState
-}
diff --git a/lib/watchfs/watchcallback.go b/lib/watchfs/watchcallback.go
deleted file mode 100644
index ab14537b..00000000
--- a/lib/watchfs/watchcallback.go
+++ /dev/null
@@ -1,9 +0,0 @@
-// SPDX-FileCopyrightText: 2019 M. Shulhan <ms@kilabit.info>
-// SPDX-License-Identifier: BSD-3-Clause
-
-package watchfs
-
-// WatchCallback is a function that will be called when Watcher or DirWatcher
-// detect any changes on its file or directory.
-// The watcher will pass the file information and its state.
-type WatchCallback func(*NodeState)
diff --git a/lib/watchfs/watcher.go b/lib/watchfs/watcher.go
index 603ee847..83cd0b4d 100644
--- a/lib/watchfs/watcher.go
+++ b/lib/watchfs/watcher.go
@@ -14,14 +14,13 @@ import (
"git.sr.ht/~shulhan/pakakeh.go/lib/memfs"
)
-const (
- defWatchDelay = 5 * time.Second
- watcherQueueSize = 16
-)
+const watcherQueueSize = 16
// Watcher is a naive implementation of file event change notification.
type Watcher struct {
- C <-chan NodeState // The channel on which the changes are delivered.
+ // The channel on which the changes are delivered.
+ C <-chan NodeState
+
qchanges chan NodeState
done chan struct{}
diff --git a/lib/watchfs/watchfs.go b/lib/watchfs/watchfs.go
index 5e283371..47a3be35 100644
--- a/lib/watchfs/watchfs.go
+++ b/lib/watchfs/watchfs.go
@@ -7,7 +7,26 @@
// The new implementation should use "watchfs/v2".
package watchfs
-import "git.sr.ht/~shulhan/pakakeh.go/lib/memfs"
+import (
+ "time"
+
+ "git.sr.ht/~shulhan/pakakeh.go/lib/memfs"
+)
+
+const defWatchDelay = 5 * time.Second
// Node represent single file or directory.
type Node = memfs.Node
+
+// NodeState contains the information about the file and its state.
+type NodeState struct {
+ // Node represent the file information.
+ Node Node
+ // State of file, its either created, modified, or deleted.
+ State FileState
+}
+
+// WatchCallback is a function that will be called when [Watcher] or
+// [DirWatcher] detect any changes on its file or directory.
+// The watcher will pass the file information and its state.
+type WatchCallback func(*NodeState)