shithub: mycel

Download patch

ref: 94389da8017a2bcca3cb29a4f954c928d577a31a
parent: fdbd295dc114a5a0c3429ecccaf665cbff5bfc66
author: Philip Silva <philip.silva@protonmail.com>
date: Fri May 28 09:18:48 EDT 2021

add an fs

--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,4 @@
-/possum
 /opossum
-/possum-src
-/possum-plan9-amd64
 *.bin
 *.out
 *.pdf
--- a/browser/website.go
+++ b/browser/website.go
@@ -11,6 +11,7 @@
 	"github.com/psilva261/opossum/nodes"
 	"github.com/psilva261/opossum/style"
 	"strings"
+	"sync"
 )
 
 const (
@@ -22,8 +23,26 @@
 	duit.UI
 	opossum.ContentType
 	d *domino.Domino
+
+	mu sync.Mutex
+	html string
+	js []string
 }
 
+func (w *Website) Html() string {
+	w.mu.Lock()
+	defer w.mu.Unlock()
+
+	return w.html
+}
+
+func (w *Website) Js() []string {
+	w.mu.Lock()
+	defer w.mu.Unlock()
+
+	return append([]string{}, w.js...)
+}
+
 func (w *Website) layout(f opossum.Fetcher, htm string, layouting int) {
 	defer func() {
 		browser.statusBarMsg("", false)
@@ -147,6 +166,11 @@
 		)
 		w.UI = scroller
 	}
+
+	w.mu.Lock()
+	w.html = htm
+	w.mu.Unlock()
+
 	log.Flush()
 }
 
--- /dev/null
+++ b/cmd/browse/fs.go
@@ -1,0 +1,46 @@
+package main
+
+import (
+	"fmt"
+	"github.com/knusbaum/go9p/fs"
+	"github.com/psilva261/opossum/browser"
+	"os/user"
+	"os"
+	"sync"
+)
+
+func Srv9p(b *browser.Browser) {
+	if err := srv9p(b); err != nil {
+		log.Errorf("srv9p: %v", err)
+	}
+}
+
+type Root struct{
+	html os.FileInfo
+	mu sync.Mutex
+	of int64
+}
+
+func srv9p(b *browser.Browser) (err error) {
+	log.Infof("srv9p")
+	u, err := user.Current()
+	if err != nil {
+		return fmt.Errorf("get user: %w", err)
+	}
+	un := u.Username
+	gn, err := group(u)
+	if err != nil {
+		return fmt.Errorf("get group: %w", err)
+	}
+	oFS, root := fs.NewFS(un, gn, 0500)
+	h := fs.NewDynamicFile(
+		oFS.NewStat("html", un, gn, 0400),
+		func() []byte {
+			return []byte(b.Website.Html())
+		},
+	)
+	root.AddChild(h)
+
+	log.Infof("post fs")
+	return post(oFS.Server())
+}
--- /dev/null
+++ b/cmd/browse/fs_plan9.go
@@ -1,0 +1,32 @@
+package main
+
+import (
+	"fmt"
+	"github.com/knusbaum/go9p"
+	"os"
+	"os/user"
+	"syscall"
+)
+
+func group(u *user.User) (string, error) {
+	return u.Gid, nil
+}
+
+func post(srv go9p.Srv) (err error) {
+	f1, f2, err := os.Pipe()
+	if err != nil {
+		return fmt.Errorf("pipe: %w", err)
+	}
+	
+	go func() {
+		err = go9p.ServeReadWriter(f1, f1, srv)
+		if err != nil {
+			log.Fatalf("serve rw: %v", err)
+		}
+	}()
+
+	if err = syscall.Mount(int(f2.Fd()), -1, "/mnt/opossum", syscall.MCREATE, ""); err != nil {
+		return fmt.Errorf("mount: %w", err)
+	}
+	return
+}
--- /dev/null
+++ b/cmd/browse/fs_unix.go
@@ -1,0 +1,22 @@
+// +build !plan9
+
+package main
+
+import (
+	"fmt"
+	"github.com/knusbaum/go9p"
+	"os/user"
+)
+
+func group(u *user.User) (string, error) {
+	g, err := user.LookupGroupId(u.Gid)
+	if err != nil {
+		return "", fmt.Errorf("get group: %w", err)
+	}
+	return g.Name, nil
+}
+
+func post(srv go9p.Srv) (err error) {
+	return go9p.PostSrv("opossum", srv)
+}
+
--- a/cmd/browse/main.go
+++ b/cmd/browse/main.go
@@ -148,6 +148,7 @@
 		return confirm(b, fmt.Sprintf("Download %v", b.URL()), "/download.file")
 	}
 	render(b, mainView(b))
+	go Srv9p(b)
 
 	for {
 		select {
--- a/go.mod
+++ b/go.mod
@@ -4,12 +4,18 @@
 
 replace 9fans.net/go v0.0.0-00010101000000-000000000000 => github.com/psilva261/go v0.0.0-20210409105224-1f229ca22d72
 
+replace 9fans.net/go v0.0.2 => github.com/psilva261/go v0.0.0-20210409105224-1f229ca22d72
+
 exclude github.com/aymerick/douceur v0.1.0
 
 exclude github.com/aymerick/douceur v0.2.0
 
+exclude github.com/hanwen/go-fuse v1.0.0
+
+exclude github.com/hanwen/go-fuse/v2 v2.0.3
+
 require (
-	9fans.net/go v0.0.0-00010101000000-000000000000
+	9fans.net/go v0.0.2
 	github.com/andybalholm/cascadia v1.1.0
 	github.com/chris-ramon/douceur v0.2.1-0.20160603235419-f3463056cd52
 	github.com/dlclark/regexp2 v1.4.0 // indirect
@@ -17,6 +23,7 @@
 	github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7
 	github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
 	github.com/gorilla/css v1.0.0 // indirect
+	github.com/knusbaum/go9p v1.17.0
 	github.com/mjl-/duit v0.0.0-20200330125617-580cb0b2843f
 	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
 	github.com/srwiley/oksvg v0.0.0-20210320200257-875f767ac39a
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,11 @@
+github.com/Plan9-Archive/libauth v0.0.0-20180917063427-d1ca9e94969d h1:xH/U6K+HYxh1480TkQYRqRO8F2RJsg+R6wFiVJzdldg=
+github.com/Plan9-Archive/libauth v0.0.0-20180917063427-d1ca9e94969d/go.mod h1:UKp8dv9aeaZoQFWin7eQXtz89iHly1YAFZNn3MCutmQ=
 github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
 github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
 github.com/chris-ramon/douceur v0.2.1-0.20160603235419-f3463056cd52 h1:xJWyi77j4VQwdeo6bO3wQSQ7o7yVwEM0ZvwXpyKHZZ8=
 github.com/chris-ramon/douceur v0.2.1-0.20160603235419-f3463056cd52/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE=
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
 github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
 github.com/dop251/goja v0.0.0-20210317175251-bb14c2267b76 h1:da/WKkWtBnwAC/DPGZQ7W2pKVEHGEyFU1u40L73DJN8=
@@ -8,14 +12,22 @@
 github.com/dop251/goja v0.0.0-20210317175251-bb14c2267b76/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
 github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7 h1:tYwu/z8Y0NkkzGEh3z21mSWggMg4LwLRFucLS7TjARg=
 github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
+github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ=
+github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
+github.com/fhs/mux9p v0.2.0 h1:R9FEaDEQjinXhAXU0D4O1DXMZM3z8rZzqhl5FnI+sxw=
+github.com/fhs/mux9p v0.2.0/go.mod h1:tjbHDrV79hmPQZ5kZ5Lu5ggNPNFe6MGAldApF+ynYy8=
 github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
 github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
 github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
 github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
+github.com/knusbaum/go9p v1.17.0 h1:K6tpQpRVmW3DzuTVAjaE5pyS+5Imv6ijj/zztCJMDY0=
+github.com/knusbaum/go9p v1.17.0/go.mod h1:2Zmddz/xhE4CFDcmV+DQIhTNAvNKUhIvj1SRaMm+P28=
 github.com/mjl-/duit v0.0.0-20200330125617-580cb0b2843f h1:eGFou1VfXmiti7EMQED6BIzfALMYi6/fBMIRL4usKfw=
 github.com/mjl-/duit v0.0.0-20200330125617-580cb0b2843f/go.mod h1:OlRagobzQ97GoM+WaQ5kyzdyts952BFYsuY5bMyv9tw=
 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/psilva261/go v0.0.0-20210409105224-1f229ca22d72 h1:uWLLj4IgtIj4iPHyiVOQLT+Qklxos2Uc7MyRP9Yo5Mc=
 github.com/psilva261/go v0.0.0-20210409105224-1f229ca22d72/go.mod h1:AWpRSZZ474OlNPxa7mOyFZ6Ceg9FRel9f+EONmhPbu0=
 github.com/srwiley/oksvg v0.0.0-20210320200257-875f767ac39a h1:Lhe6HPtH4ndWfV56fWc4/yQhOP3vEGlwl5nfPyBxUAg=
@@ -22,11 +34,15 @@
 github.com/srwiley/oksvg v0.0.0-20210320200257-875f767ac39a/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4=
 github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 h1:m59mIOBO4kfcNCEzJNy71UkeF4XIx2EVmL9KLwDQdmM=
 github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
 golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
 golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E=
 golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
+golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -36,5 +52,6 @@
 golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
binary files /dev/null b/opossum.jpg differ
--- a/package.rc
+++ b/package.rc
@@ -16,7 +16,7 @@
 mv cmd/browse/$name.bin .
 mv $name.bin ./$name/
 cp README.md ./$name/
-cp possum-655x493.jpg ./$name/
+cp opossum.jpg ./$name/
 tarball=`{pwd} ^ '/packages/' ^ $name ^ '-v0.0.1-' ^ `{date -i} ^ '-' ^ `{cat /mnt/git/branch/heads/master/hash | read -c 6} ^ '.tgz'
 tar czf $tarball $name
 chmod +t $tarball
binary files a/possum-655x493.jpg /dev/null differ