wip of watching for changes
Ted Unangst tedu@tedunangst.com
Sat, 25 Nov 2023 16:32:22 -0500
M
go.sum
→
go.sum
@@ -48,7 +48,7 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/pledge v0.1.5 h1:YajAbytcCFeGtrUBagOC6QjxRpGaVRg0k80Y2IAh/Ss= -humungus.tedunangst.com/r/pledge v0.1.5/go.mod h1:Bz/UgrjLr/nY5sgI8LIZ8oBg/YqEi/hHi+NPetojXYM= +humungus.tedunangst.com/r/gonix v0.1.0 h1:OSMxmNPPeS5PU6uiqfn1ZdYhGg6fkWI6g1oGHwr9Ka8= +humungus.tedunangst.com/r/gonix v0.1.0/go.mod h1:VFBc2bPDXr1ayHOmHUutxYu8fSM+pkwK8o36h4rkORg= humungus.tedunangst.com/r/webs v0.7.9 h1:LC9o2F9joAcf4SxWaRFs5ZqXHSbzdfre9/9BY0gcM0w= humungus.tedunangst.com/r/webs v0.7.9/go.mod h1:ylhqHSPI0Oi7b4nsnx5mSO7AjLXN7wFpEHayLfN/ugk=
M
unveil.go
→
unveil.go
@@ -16,36 +16,36 @@
package main import ( - "humungus.tedunangst.com/r/pledge" + "humungus.tedunangst.com/r/gonix" ) func securitizeweb() { - err := pledge.Unveil("/etc/ssl", "r") + err := gonix.Unveil("/etc/ssl", "r") if err != nil { elog.Fatalf("unveil(%s, %s) failure (%d)", "/etc/ssl", "r", err) } if viewDir != dataDir { - err = pledge.Unveil(viewDir, "r") + err = gonix.Unveil(viewDir, "r") if err != nil { elog.Fatalf("unveil(%s, %s) failure (%d)", viewDir, "r", err) } } - err = pledge.Unveil(dataDir, "rwc") + err = gonix.Unveil(dataDir, "rwc") if err != nil { elog.Fatalf("unveil(%s, %s) failure (%d)", dataDir, "rwc", err) } - pledge.UnveilEnd() + gonix.UnveilEnd() promises := "stdio rpath wpath cpath flock dns inet unix" - err = pledge.Pledge(promises) + err = gonix.Pledge(promises) if err != nil { elog.Fatalf("pledge(%s) failure (%d)", promises, err) } } func securitizebackend() { - pledge.UnveilEnd() + gonix.UnveilEnd() promises := "stdio unix" - err := pledge.Pledge(promises) + err := gonix.Pledge(promises) if err != nil { elog.Fatalf("pledge(%s) failure (%d)", promises, err) }
M
web.go
→
web.go
@@ -38,6 +38,7 @@ "time"
"unicode/utf8" "github.com/gorilla/mux" + "humungus.tedunangst.com/r/gonix" "humungus.tedunangst.com/r/webs/cache" "humungus.tedunangst.com/r/webs/gencache" "humungus.tedunangst.com/r/webs/httpsig"@@ -2759,6 +2760,32 @@
return fmt.Sprintf("?v=%.8x", hasher.Sum(nil)) } +func startWatcher() { + watcher, err := gonix.NewWatcher() + if err != nil { + elog.Printf("can't watch: %s", err) + return + } + go func() { + s := dataDir + "/views/local.css" + for { + err := watcher.WatchFile(s) + if err != nil { + dlog.Printf("can't watch: %s", err) + break + } + err = watcher.WaitForChange() + if err != nil { + dlog.Printf("can't wait: %s", err) + break + } + dlog.Printf("local.css changed") + delete(savedassetparams, s) + savedassetparams[s] = getassetparam(s) + } + }() +} + var usefcgi bool func serve() {@@ -2811,6 +2838,7 @@ savedassetparams[s] = getassetparam(s)
} loadAvatarColors() } + startWatcher() securitizeweb()