Beispiel #1
0
/*
	Create a new empty name space. It has a single entry for an empty
	directory mounted at "/"
*/
func New() *Tree {
	ns := &Tree{
		pref: []*prefix{
			{name: "/"},
		},
	}
	ns.pref[0].ns = ns
	ns.dprintf = dbg.FlagPrintf(os.Stderr, &ns.Debug)
	ns.dfprintf = dbg.FlagPrintf(os.Stderr, &ns.DebugFind)
	return ns
}
Beispiel #2
0
// Make a new repl for the given name and local and remote tree addresses.
// Pred defaults to exclude all dot files and dirs: 'name~^\.&prune|true'
func New(name, pred, laddr, raddr string) (*Repl, error) {
	r := &Repl{
		Name: name,
		Laddr: laddr,
		Raddr: raddr,
		pred: pred,
	}
	r.vprintf = dbg.FlagPrintf(os.Stdout, &r.Verb)
	if err := r.dial(); err != nil {
		return nil, err
	}
	var err, rerr error
	r.Ldb, err = sync.NewDB(name + "[" + laddr + "]", pred, r.lfs)
	if err != nil {
		dbg.Warn("%s: %s", laddr, err)
	}
	r.Rdb, rerr = sync.NewDB(name + "[" + raddr + "]", pred, r.rfs)
	if rerr != nil {
		err = rerr
		dbg.Warn("%s: %s", raddr, rerr)
	}
	r.Ldb.Pred = r.pred
	r.Rdb.Pred = r.pred
	return r, err
}
Beispiel #3
0
// Load the repl config and metadata dbs from disk.
func Load(fname string) (*Repl, error) {
	dat, err := ioutil.ReadFile(fname)
	if err != nil {
		return nil, err
	}
	cs := string(dat)
	lns := strings.Split(cs, "\n")
	if len(lns) < 4 {
		return nil, errors.New("too few lines in cfg")
	}
	r := &Repl{
		Name: lns[0],
		pred: lns[1],
		Laddr: lns[2],
		Raddr: lns[3],
	}
	r.vprintf = dbg.FlagPrintf(os.Stdout, &r.Verb)
	if err := r.dial(); err != nil {
		return nil, err
	}
	if r.Ldb, err = sync.LoadDB(fname+"l.db"); err != nil {
		return nil, err
	}
	if r.Rdb, err = sync.LoadDB(fname+"r.db"); err != nil {
		return nil, err
	}
	r.Ldb.Pred = r.pred
	r.Rdb.Pred = r.pred
	return r, nil
}
Beispiel #4
0
// Serve serves a FUSE connection with the default settings. See
// Server.Serve.
func Serve(c *fuse.Conn, fs FS) error {
	server := Server{
		FS:      fs,
		dprintf: dbg.FlagPrintf(os.Stderr, &Debug),
	}
	return server.Serve(c)
}
Beispiel #5
0
	"clive/zx/cfs"
	"clive/zx/lfs"
	"clive/zx/mfs"
	"clive/zx/rfs"
	"errors"
	"fmt"
	"os"
	"path"
	"path/filepath"
	"strings"
)

var (
	Verbose, Debug, Zdebug bool

	Dprintf = dbg.FlagPrintf(os.Stdout, &Debug)
	Vprintf = dbg.FlagPrintf(os.Stdout, &Verbose)

	opts  = opt.New("{spec}")
	port  string
	wport string
	svc   string
	addr  string

	zxw = map[string]string{}
)

func zxwax() {
	ctrl := ctl.NewControl()
	ctrl.BoolFlag("Debug", &Debug)
	ctrl.CmdFlag("Exit", func() {
Beispiel #6
0
package frmt

import (
	"clive/dbg"
	"strings"
	"testing"
)

var (
	debug   bool
	dprintf = dbg.FlagPrintf(&debug)
)

func TestWords(t *testing.T) {
	txt := []string{` a te`, `xt wit`, `h`, `
  some`, `
spaces `, `and words `,
	}
	sc, rc := Words()
	go func() {
		for _, t := range txt {
			sc <- t
		}
		close(sc)
	}()
	words := []string{}
	for w := range rc {
		ws := string(w)
		dprintf("word [%s]\n", ws)
		words = append(words, ws)
	}
Beispiel #7
0
	"clive/app"
	"clive/app/opt"
	"clive/app/ql/qlfs"
	"clive/dbg"
	"clive/zx"
	"clive/zx/rfs"
	"clive/zx/zxfs"
	"os"
)

var (
	sflag       bool
	opts        = opt.New("[mntdir] &")
	addr, xaddr string
	mntdir      = "/n/ql"
	dprintf     = dbg.FlagPrintf(os.Stderr, &zxfs.Debug)
)

func main() {
	defer app.Exiting()
	x := app.New()
	stacks := false
	opts.NewFlag("F", "debug fuse requests", &zxfs.Debug)
	opts.NewFlag("D", "debug", &x.Debug)
	opts.NewFlag("s", "statistics", &sflag)
	opts.NewFlag("x", "addr: re-export locally the ql tree to this address", &xaddr)
	opts.NewFlag("S", "dump stacks on unmount for debugging", &stacks)
	args, err := opts.Parse(x.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
Beispiel #8
0
//line parse.y:6
package xp

import __yyfmt__ "fmt"

//line parse.y:6
import (
	"clive/dbg"
	"math"
	"os"
	"time"
)

var (
	debugYacc bool
	yprintf   = dbg.FlagPrintf(os.Stderr, &debugYacc)
	lvl       int
	result    value
)

//line parse.y:24
type yySymType  {
	yys  int
	ival uint64
	fval float64
	sval string
	tval time.Time
	vval interface{}
}

const INT = 57346
Beispiel #9
0
package fscmp

import (
	"clive/dbg"
	"clive/zx/fstest"
	"clive/zx/zux"
	"fmt"
	"os"
	"testing"
)

var (
	tdir   = "/tmp/fscmptest"
	tdir2  = "/tmp/fscmptest2"
	Verb   bool
	Printf = dbg.FlagPrintf(&fstest.Verb)
)

func TestDiffs(t *testing.T) {
	os.Args[0] = "fscmp.test"
	fstest.Verb = testing.Verbose()
	fstest.MkTree(t, tdir)
	fstest.MkChgs(t, tdir)
	defer os.RemoveAll(tdir)
	fstest.ResetTime()
	fstest.MkTree(t, tdir2)
	fstest.MkChgs2(t, tdir2)
	defer os.RemoveAll(tdir2)

	Printf("changes...\n")
	fs, err := zux.NewZX(tdir)
Beispiel #10
0
	tTime    tok = TIME
	tSleft tok = SLEFT
	tSright tok = SRIGHT
)

type lex  {
	in     []rune
	p0, p1 int

	wasfunc, wasattr bool
	result interface{}
}

var (
	debugLex bool
	lprintf  = dbg.FlagPrintf(os.Stderr, &debugLex)
)

func newLex(input string) *lex {
	return &lex{
		in: []rune(input),
	}
}

func (l *lex) Error(s string) {
	panic(fmt.Errorf("near %s: %s", l.val(), s))
}

func (l *lex) get() rune {
	if l.p1 >= len(l.in) {
		return 0
Beispiel #11
0
import (
	"bytes"
	"clive/dbg"
	"clive/nchan"
	"errors"
	"fmt"
	"io"
	"os"
	"path"
	"strconv"
	"strings"
)

var DebugSend bool // set to debug sends/receives of full trees
var dprintf = dbg.FlagPrintf(os.Stderr, &DebugSend)

func BadName(elem string) error {
	if strings.Contains(elem, "/") || elem == "." || elem == ".." {
		return fmt.Errorf("bad element name '%s'", elem)
	}
	return nil
}

// Make sure s is an abslute path and return it cleaned and never empty.
func AbsPath(s string) (string, error) {
	if len(s) == 0 || s[0] != '/' {
		return "", fmt.Errorf("'%s' is not an absolute path", s)
	}
	return path.Clean(s), nil
}
Beispiel #12
0
	Bin string	// restart if the binary changes
	Env map[string]string
	x *exec.Cmd
	name string	// Base(dir)
	dir string	// path of the dir for the cmd
	runt time.Time	// start time

	donec chan bool
	sigrestart bool
	bint time.Time
}

var (
	opts = opt.New("")
	debug, verb bool
	dprintf = dbg.FlagPrintf(os.Stderr, &debug)
	vprintf = dbg.FlagPrintf(os.Stderr, &verb)
	shell = "rc"
	dir = "/tmp/xcmd"
	cmd1 string
	ErrNotYet = errors.New("not ready to start")
	ErrExited = errors.New("command has exited")
	ErrRestart = errors.New("restart required")
)


func walk(ds []os.FileInfo, name string) os.FileInfo {
	for _, d := range ds {
		if d.Name() == name {
			return d
		}
Beispiel #13
0
	"clive/zx/fstest"
	"clive/zx/rzx"
	"clive/zx/zux"
	"clive/zx/zxc"
	"fmt"
	"os"
	fpath "path"
	"strings"
	"testing"
)

const tdir = "/tmp/ns_test"

var (
	verb     = false
	printf   = dbg.FlagPrintf(&verb)
	moreverb = false
	ns1      = `/ /
/tmp
/tmp	lfs!/!/tmp
/tmp	lfs!/tmp
/usr
/usr/nemo	zx!unix!8089!/tmp
path:"/x"	io:"0"	addr:"zx!unix!8089!/tmp"
`

	ns1out = `/
/tmp
/tmp	lfs!/!/tmp
/tmp
/usr
Beispiel #14
0
	Name   string    // of the db
	Root   *File     // root
	Pred string	// find predicate.
	lastpf   *File
	lastpdir string
}

// a File in the metadata DB
type File  {
	D     zx.Dir  // for the file
	Child []*File // for directories
}

var (
	Debug, Verb bool
	dprintf = dbg.FlagPrintf(os.Stderr, &Debug)
	vprintf = dbg.FlagPrintf(os.Stderr, &Verb)
)

// predicate to exclude dot files from dbs.
const NoDots = `name~^\.&prune|true`

// Create a DB for the given tree with the given name.
func NewDB(name, pred string, fs Finder) (*DB, error) {
	t := &DB{
		Name: name,
		Pred: pred,
	}
	err := t.scan(fs)
	return t, err
}
Beispiel #15
0
type Bg  {
	seq  int
	Nds  map[*Nd]bool
	Tags map[string]int
	sync.Mutex
	waits map[string][]chan bool
}

var (
	bg = &Bg{
		Nds:   map[*Nd]bool{},
		Tags:  map[string]int{},
		waits: map[string][]chan bool{},
	}
	debugExec bool
	xprintf   = dbg.FlagPrintf(os.Stderr, &debugExec)

	intrlk      sync.Mutex
	intrc       chan bool // closed upon interrupts
	Interrupted bool      // set to true upon interrupts
	IntrExits   bool      // set to true when running scripts
	ErrIntr     = errors.New("interrupted")
)

func init() {
	intrlk.Lock()
	intrc = make(chan bool)
	intrlk.Unlock()
	dbg.AtIntr(func() bool {
		dprintf("*** SIGINT\n")
		intrlk.Lock()
Beispiel #16
0
	"net/http"
	"os"
	"path"
	"sync"
)

/*
	From where to fetch js code and related files.
*/
var JSpath = "/Users/nemo/gosrc/src/clive/net/wax"

var (
	started   bool
	startedlk sync.Mutex
	Verbose   bool
	vprintf   = dbg.FlagPrintf(os.Stderr, &Verbose)
)

func jsHandler(w http.ResponseWriter, r *http.Request) {
	p := path.Clean(r.URL.Path)
	p = path.Join(JSpath, p)
	vprintf("serving %s\n", p)
	http.ServeFile(w, r, p)
}

/*
	Start the wax web server.
*/
func Serve(port string) error {
	startedlk.Lock()
	defer startedlk.Unlock()