M8 networkmanager: the folder's unknown is the module's

The folder the two parts share says unknown module, so the node-engine does nothing
inside it and the watcher reacts: a path it does not know is left as it is and written
to its journal once per path, at its start and at the file event that makes it; the
README says so.

Builds: design 08 sign-in-page §12, §24, §25, §27; lead answer L-1 (hq 3a3a18a9)
This commit is contained in:
jochen
2026-11-24 21:31:51 +01:00
parent dd35217275
commit e20d3c7548
7 changed files with 184 additions and 4 deletions
@@ -0,0 +1,60 @@
package main
// A path in the module's folder the watcher does not know (design 08 sign-in-page §12; lead answer L-1): the folder's
// `unknown` is `module`, so the node-engine does nothing inside it and the watcher reacts. It leaves such a path as it
// is and writes it to its journal once per path: at its start for what is there, and at each file event of the kernel
// that makes one.
import (
"os"
"path/filepath"
"regexp"
"strings"
)
// keptFile is a kept event's name in pending/, or one being written beside it.
var keptFile = regexp.MustCompile(`^[0-9]{10}\.json(\.new)?$`)
// knownPath says whether path is one of the folder's own: watch.sock, check-address, pending/ and its files,
// names.json, sequence, or a file being written beside one of them.
func (f Folder) knownPath(path string) bool {
rel, err := filepath.Rel(f.Dir, path)
if err != nil || strings.HasPrefix(rel, "..") {
return false
}
dir, name := filepath.Split(rel)
switch dir {
case "":
name = strings.TrimSuffix(name, ".new")
return name == socketName || name == checkName || name == pendingName || name == namesName || name == sequenceName
case pendingName + "/":
return keptFile.MatchString(name)
}
return false
}
// unknownAtStart is every path in the folder and in pending/ the watcher does not know.
func (f Folder) unknownAtStart() []string {
var out []string
for _, dir := range []string{f.Dir, filepath.Join(f.Dir, pendingName)} {
entries, _ := os.ReadDir(dir)
for _, e := range entries {
if p := filepath.Join(dir, e.Name()); !f.knownPath(p) {
out = append(out, p)
}
}
}
return out
}
// strange writes a path the watcher does not know to its journal, once per path, and leaves it as it is.
func (w *Watcher) strange(path string) {
if w.Folder.knownPath(path) || w.told[path] {
return
}
if w.told == nil {
w.told = map[string]bool{}
}
w.told[path] = true
journal("%s is not the module's: left as it is", path)
}