Exemple #1
0
func list(name string) error {
	if !strings.ContainsRune(name, '/') {
		name = "/u/lib/repl/" + name
	}
	tr, err := repl.Load(name)
	if err != nil {
		return err
	}
	defer tr.Close()
	c := cmd.AppCtx()
	switch {
	case c.Verb:
		tr.Ldb.DumpTo(os.Stderr)
		tr.Rdb.DumpTo(os.Stderr)
	default:
		xs := strings.Join(tr.Ldb.Excl, " ")
		cmd.Printf("%s %s %s %s\n", tr.Ldb, tr.Ldb.Addr, tr.Rdb.Addr, xs)
	}
	return nil
}
Exemple #2
0
func pull1(name string) error {
	if !strings.ContainsRune(name, '/') {
		name = "/u/lib/repl/" + name
	}
	tr, err := repl.Load(name)
	if err != nil {
		cmd.Warn("load %s: %s", name, err)
		return err
	}
	defer tr.Close()
	c := cmd.AppCtx()
	if c.Debug {
		tr.Ldb.DumpTo(os.Stderr)
		tr.Rdb.DumpTo(os.Stderr)
	}
	if nflag {
		var cc <-chan repl.Chg
		switch {
		case aflag:
			cc, err = tr.AllPullChanges()
		default:
			cc, err = tr.PullChanges()
		}
		if err != nil {
			cmd.Warn("pull changes %s: %s", name, err)
			return err
		}
		for c := range cc {
			cmd.Printf("%s\n", c)
		}
		return nil
	}
	var cc chan repl.Chg
	dc := make(chan bool)
	if c.Verb {
		cc = make(chan repl.Chg)
		go func() {
			for c := range cc {
				cmd.Printf("%s\n", c)
			}
			close(dc)
		}()
	} else {
		close(dc)
	}
	switch {
	case aflag:
		err = tr.PullAll(cc)
	case bflag:
		err = tr.BlindPull(cc)
	default:
		err = tr.Pull(cc)
	}
	<-dc
	if err != nil {
		cmd.Warn("pull %s: %s", name, err)
	}
	if err2 := tr.Save(name); err2 != nil {
		cmd.Warn("save %s: %s", name, err2)
		if err == nil {
			err = err2
		}
	}
	return err
}