ref: 8425df6daf1bd75c6cfb82683dc278d0831bd33a
parent: 616c65b0e59735510eb1fdd0d0813a9ba84d613e
author: Philip Silva <[email protected]>
date: Fri Jul 16 11:03:02 EDT 2021
Improved locking in fs pkg
--- a/browser/browser.go
+++ b/browser/browser.go
@@ -690,7 +690,7 @@
// makeLink of el and its children
func (el *Element) makeLink(href string) {
- if href == "" || strings.HasPrefix(href, "#") || strings.Contains(href, "javascript:void(0)") {
+ if href == "" || strings.HasPrefix(href, "#") || strings.HasPrefix(href, "javascript:") {
return
}
--- a/browser/fs/fs.go
+++ b/browser/fs/fs.go
@@ -17,8 +17,10 @@
)
var (
- log *logger.Logger
- mu sync.RWMutex
+ log *logger.Logger
+ mu *sync.RWMutex
+ c *sync.Cond
+
oFS *fs.FS
un string
gn string
@@ -34,16 +36,23 @@
Query(q string) ([]*nodes.Node, error)
}
+func init() {
+ mu = &sync.RWMutex{}
+ c = sync.NewCond(mu)
+}
+
func SetLogger(l *logger.Logger) {
log = l
}
func Srv9p() {
+ c.L.Lock()
var root *fs.StaticDir
u, err := user.Current()
if err != nil {
log.Errorf("get user: %v", err)
+ c.L.Unlock()
return
}
un = u.Username
@@ -50,6 +59,7 @@
gn, err = opossum.Group(u)
if err != nil {
log.Errorf("get group: %v", err)
+ c.L.Unlock()
return
}
oFS, root = fs.NewFS(un, gn, 0500)
@@ -66,6 +76,7 @@
d, err := fs.CreateStaticDir(oFS, root, un, "css", 0500|proto.DMDIR, 0)
if err != nil {
log.Errorf("create static dir: %v", err)
+ c.L.Unlock()
return
}
cssDir = d.(*fs.StaticDir)
@@ -73,6 +84,7 @@
d, err = fs.CreateStaticDir(oFS, root, un, "js", 0500|proto.DMDIR, 0)
if err != nil {
log.Errorf("create static dir: %v", err)
+ c.L.Unlock()
return
}
jsDir = d.(*fs.StaticDir)
@@ -87,6 +99,9 @@
lxhr := (*fs.ListenFileListener)(xhr)
go Xhr(lxhr)
}
+ c.Broadcast()
+ c.L.Unlock()
+
if err := post(oFS.Server()); err != nil {
log.Errorf("srv9p: %v", err)
}
@@ -181,8 +196,12 @@
}
func Update(htm string, css []string, js []string) {
- mu.Lock()
- defer mu.Unlock()
+ c.L.Lock()
+ defer c.L.Unlock()
+
+ if cssDir == nil && jsDir == nil {
+ c.Wait()
+ }
html = htm
if cssDir != nil {
--- a/cmd/gojafs/domino/domino.go
+++ b/cmd/gojafs/domino/domino.go
@@ -152,7 +152,9 @@
func (d *Domino) Exec(script string, initial bool) (res string, err error) {
r := regexp.MustCompile(`^\s*<!--`)
+ rr := regexp.MustCompile(`-->\s*$`)
script = r.ReplaceAllString(script, "//")
+ script = rr.ReplaceAllString(script, "//")
SCRIPT := domIntf + script
if !initial {
SCRIPT = script
--- a/cmd/gojafs/domino/domino_test.go
+++ b/cmd/gojafs/domino/domino_test.go
@@ -336,7 +336,7 @@
''.replace(/^\s*<!--/g, '');
const a = 1;
a + 7;
-// -->
+-->
`
res, err := d.Exec(script, true)
if err != nil {