當前位置: 首頁>>代碼示例>>Golang>>正文


Golang zx.Dir類代碼示例

本文整理匯總了Golang中clive/zx.Dir的典型用法代碼示例。如果您正苦於以下問題:Golang Dir類的具體用法?Golang Dir怎麽用?Golang Dir使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Dir類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: chkdirs

func chkdirs(t Fataler, fs zx.Tree, d zx.Dir, recur bool) {
	if d["path"] == "" {
		t.Fatalf("no path in <%s>", d)
	}
	if d["type"] != "d" {
		return
	}
	dents, err := zx.GetDir(fs, d["path"])
	if err != nil {
		t.Fatalf("getdir: %s: %s", d["path"], err)
	}
	if d["size"] != fmt.Sprintf("%d", len(dents)) {
		t.Logf("%s: size %s len(dents) %d", d["path"], d["size"], len(dents))
		t.Logf("d: %s\n", d.Long())
		for _, cd := range dents {
			t.Logf("\t%s\n", cd.Long())
		}
		t.Fatalf("bad dir size")
	}
	if recur {
		for _, cd := range dents {
			chkdirs(t, fs, cd, true)
		}
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:25,代碼來源:fstest.go

示例2: DirFs

// Dial the server for this dir (if not already dialed) and return it,
// the dir addr is updated.
func DirFs(d zx.Dir) (zx.Fs, error) {
	switch p := d.Proto(); p {
	case "lfs":
		addr := d["addr"]
		toks := strings.Split(d["addr"], "!") // lfs!root!/path
		if len(toks) != 3 {
			return nil, fmt.Errorf("ns: no zux tree for addr %q", addr)
		}
		fullpath := fpath.Join(toks[1], toks[2])
		fs, root, rel := Lfs(fullpath)
		if fs == nil {
			return nil, fmt.Errorf("ns: no zux tree for addr %q", addr)
		}
		d["addr"] = "lfs!" + root + "!" + rel
		return fs, nil
	case "zx":
		addr := d.SAddr()
		if len(addr) < 3 {
			panic("DirFs bug")
		}
		addr = addr[3:] // remove zx!
		// rzx does cache dials, no need to do it again here.
		return rzx.Dial(addr, auth.TLSclient)
	default:
		return nil, fmt.Errorf("ns: no tree for addr %q", d["addr"])
	}
}
開發者ID:chengguozhen,項目名稱:clive,代碼行數:29,代碼來源:file.go

示例3: wstat

func (t *Fs) wstat(rid string, d zx.Dir) error {
	f, err := t.walk(rid)
	if err != nil {
		return err
	}
	ud := d.UsrAttrs()
	d, err = f.Stat()
	if err != nil {
		return err
	}
	ai := t.ai
	if t.NoPermCheck {
		ai = nil
	}
	if !t.WstatAll || t.ai != nil {
		if err := d.CanWstat(ai, ud); err != nil {
			return err
		}
	}
	if wsf, ok := f.(Wstater); !ok {
		if _, ok := f.(Putter); !ok {
			return fmt.Errorf("%s: %s", rid, dbg.ErrPerm)
		}
		// ignore wstats if there's Put so that echo > file works.
		return nil
	} else {
		return wsf.Wstat(ud)
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:29,代碼來源:vfs.go

示例4: ch

func ch(d, nd zx.Dir) error {
	if nd["mode"] != "" {
		nd = nd.Dup()
		chmod(d, nd["mode"])
	}
	_, err := cmd.Wstat(d["path"], nd)
	return err
}
開發者ID:chengguozhen,項目名稱:clive,代碼行數:8,代碼來源:ch.go

示例5: mv1

func mv1(src, dst zx.Dir) error {
	cmd.VWarn("%s %s", src["Upath"], dst["Upath"])
	cmd.Dprintf("mv1: %s %s %s %s\n", src.SAddr(), src["Rpath"], dst.SAddr(), dst["Rpath"])
	if dry {
		return nil
	}
	return cmd.Move(src["path"], dst["path"])
}
開發者ID:chengguozhen,項目名稱:clive,代碼行數:8,代碼來源:mvf.go

示例6: FindAt

/*
	Execute the part of the ns.Find operation that evaluates p
	at the tree rooted at d (considering that its level is the one
	indicated). Found entries are sent through the given channel,
	which is closed only upon errors.

	This is useful to implement ns.Find when writting services.
*/
func (p *Pred) FindAt(fs zx.Sender, d zx.Dir, c chan<- zx.Dir, lvl int) {
	match, pruned, err := p.EvalAt(d, lvl)
	if err != nil {
		close(c, err)
		return
	}
	if pruned {
		nd := d.Dup()
		nd["err"] = "pruned"
		c <- nd
		return
	}
	if d["rm"] != "" {
		return
	}
	var ds []zx.Dir
	if d["type"] == "d" {
		ds, err = zx.GetDir(fs, d["path"])
	}
	if err != nil {
		nd := d.Dup()
		nd["err"] = err.Error()
		c <- nd
		return
	}
	if match {
		if ok := c <- d; !ok {
			return
		}
	}
	for i := 0; i < len(ds); i++ {
		cd := ds[i]
		if cd["rm"] != "" {
			continue
		}
		p.FindAt(fs, cd, c, lvl+1)
	}
}

func Find(fs zx.Tree, path, pred string) <-chan zx.Dir {
	c := make(chan zx.Dir)
	go func() {
		d, err := zx.Stat(fs, path)
		if d == nil {
			close(c, err)
			return
		}
		x, err := New(pred)
		if err != nil {
			close(c, err)
			return
		}
		x.FindAt(fs, d, c, 0)
		close(c)
	}()
	return c
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:65,代碼來源:pred.go

示例7: metaChanged

// does not check attributes that indicate that data changed.
func metaChanged(d0, d1 zx.Dir) bool {
	ud0 := d0.UsrAttrs()
	ud1 := d1.UsrAttrs()
	for _, k := range ignoredAttrs {
		delete(ud0, k)
		delete(ud1, k)
	}
	return !zx.EqDir(ud0, ud1)
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:10,代碼來源:cmp.go

示例8: newDir

// Make a new Dir form a zd.Dir
func (z *Cfs) newDir(d zx.Dir) *Dir {
	zd := &Dir{
		z:     z,
		d:     d,
		path:  d["path"],
		mode:  uint(d.Uint64("mode")&0777),
		epoch: *z.epoch,
	}
	if zd.mode == 0 {
		zd.mode = 0777
	}
	return zd
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:14,代碼來源:dir.go

示例9: Gets

func Gets(t Fataler, fss ...zx.Tree) {
	for i := 0; i < Repeats; i++ {
		for _, fs := range fss {
			for _, p := range GetFPaths {
				printf("getall %s\n", p)
				dat, err := zx.GetAll(fs, p)
				if err != nil {
					t.Fatalf("get %s: %s", p, err)
				}
				printf("got %d bytes \n\n", len(dat))
				if string(dat) != string(FileData[p]) {
					printf("got <%s>\nexpected<%s>\n",
						string(dat), string(FileData[p]))
					t.Fatalf("%s: bad data", p)
				}
			}

			for _, p := range GetDPaths {
				printf("getall %s\n", p)
				dat, err := zx.GetAll(fs, p)
				if err != nil {
					t.Fatalf("get %s: %s", p, err)
				}
				var d zx.Dir
				ents := []string{}
				for len(dat) > 0 {
					d, dat, err = zx.UnpackDir(dat)
					if err != nil {
						t.Fatalf("dir: %s", err)
					}
					if d["path"] == "/Ctl" || d["path"] == "/Chg" {
						continue
					}
					ents = append(ents, d.TestFmt())
				}
				if strings.Join(GetDOuts[p], "\n") != strings.Join(ents, "\n") {
					t.Fatalf("bad dir data for %s", p)
				}
				printf("got %d ents (ctl, chg excluded)\n", len(ents))
			}
			for _, p := range BadPaths {
				dat, err := zx.GetAll(fs, p)
				if err==nil || len(dat)>0 {
					t.Fatalf("get %s didn't fail", p)
				}
			}
			printf("\n")
		}
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:50,代碼來源:fstest.go

示例10: put

func (t *Fs) put(rid string, d zx.Dir, off int64, dc <-chan []byte, pred string) error {
	pf, err := t.walk(path.Dir(rid))
	if err != nil {
		return err
	}
	pd, err := pf.Stat()
	if pd["type"] != "d" {
		return fmt.Errorf("%s: %s", pd["path"], dbg.ErrNotDir)
	}
	wpf, ok := pf.(Walker)
	if !ok {
		return fmt.Errorf("%s: %s", pd["path"], dbg.ErrPerm)
	}
	f, err := wpf.Walk(path.Base(rid))
	if err != nil && !dbg.IsNotExist(err) {
		return err
	}
	if err != nil {
		if err := t.matchDir(rid, nil, pred); err != nil {
			return err
		}
		if !t.NoPermCheck && !pd.CanWrite(t.ai) {
			return fmt.Errorf("%s: %s", rid, dbg.ErrPerm)
		}
		if putf, ok := pf.(Putter); ok {
			return putf.Put(path.Base(rid), d, off, dc)
		}
		return fmt.Errorf("%s: %s", pd["path"], dbg.ErrPerm)
	} else {
		d, err := f.Stat()
		if err != nil {
			return err
		}
		if d["type"] == "d" {
			return fmt.Errorf("%s: %s", rid, dbg.ErrIsDir)
		}
		if err := t.matchDir(rid, d, pred); err != nil {
			return err
		}
		if !t.NoPermCheck && !d.CanWrite(t.ai) {
			return fmt.Errorf("%s: %s", rid, dbg.ErrPerm)
		}
		if putf, ok := f.(Putter); ok {
			return putf.Put("", d, off, dc)
		}
		return fmt.Errorf("%s: %s", d["path"], dbg.ErrPerm)
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:48,代碼來源:vfs.go

示例11: walk

func (t *Fs) walk(rid string) (File, error) {
	rid, err := zx.AbsPath(rid)
	if err != nil {
		return nil, err
	}
	if rid == "/" {
		return t.root, nil
	}
	if rid == "/Ctl" {
		return nil, nil
	}
	els := zx.Elems(rid)
	f := t.root
	p := "/"
	var d zx.Dir
	for _, e := range els {
		t.Dprintf("walk %s %s...\n", f, e)
		d, err = f.Stat()
		if err != nil {
			t.Dprintf("\tstat: %s\n", f, err)
			return nil, err
		}
		if d["type"] != "d" {
			t.Dprintf("\tnot dir\n")
			return nil, fmt.Errorf("%s: %s", p, dbg.ErrNotDir)
		}
		if !t.NoPermCheck && !d.CanWalk(t.ai) {
			t.Dprintf("\tno perm\n")
			return nil, fmt.Errorf("%s: %s", p, dbg.ErrPerm)
		}
		wf, ok := f.(Walker)
		if !ok {
			t.Dprintf("\tnot walker\n")
			return nil, fmt.Errorf("%s: %s: %s", p, e, dbg.ErrNotExist)
		}
		f, err = wf.Walk(e)
		if err != nil {
			t.Dprintf("\twalk: %s\n", err)
			return nil, err
		}
		p = zx.Path(p, e)
		t.Dprintf("walked %s\n", f)
	}
	return f, nil
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:45,代碼來源:vfs.go

示例12: rmf

func rmf(d zx.Dir) error {
	p := d.SPath()
	up := d["Upath"]
	if up == "" {
		up = d["path"]
	}
	if p == "" || p == "/" {
		cmd.Fatal("won't remove / in server for '%s'", up)
	}
	cmd.VWarn("rmf%s %s", astr[aflag], up)
	if dry {
		return nil
	}
	if aflag {
		return cmd.RemoveAll(d["path"])
	}
	return cmd.Remove(d["path"])
}
開發者ID:fjballest,項目名稱:clive,代碼行數:18,代碼來源:rmf.go

示例13: Put

func (t *Fs) Put(rid string, d zx.Dir, off int64, dc <-chan []byte, pred string) chan zx.Dir {
	d = d.Dup()
	t.dprintf("put %s %v %d '%s'\n", rid, d, off, pred)
	cs := t.IOstats.NewCall(zx.Sput)
	c := make(chan zx.Dir, 1)
	go func() {
		cs.Sending()
		rid, err := zx.AbsPath(rid)
		var nm, n int64
		var nd zx.Dir
		if err == nil && rid == "/Ctl" {
			nc, xerr := t.putCtl(dc)
			if xerr == nil {
				nd = zx.Dir{"size": "0"}
				if DoSum {
					nd["Sum"] = zx.Zsum()
				}
				nd.SetTime("mtime", time.Now())
				nm = 1
				n = int64(nc)
			}
			err = xerr
		} else if err == nil {
			nd, nm, n, err = t.put(rid, d, off, dc, pred)
			cs.Sends(nm, n)
		}
		if err == nil {
			rd := zx.Dir{"size": nd["size"], "mtime": nd["mtime"]}
			if nd["Sum"] != "" {
				rd["Sum"] = nd["Sum"]
			}
			t.dprintf("put %s: %s (wrote %d)\n", rid, rd, n)
			c <- rd
		} else {
			t.dprintf("put %s: %s\n", rid, err)
			close(dc, err)
		}
		close(c, err)
		cs.End(err != nil)
	}()
	return c
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:42,代碼來源:mfs.go

示例14: Get

func (t *Fs) Get(rid string, off, count int64, pred string) <-chan []byte {
	t.dprintf("get %s %d %d %q\n", rid, off, count, pred)
	cs := t.IOstats.NewCall(zx.Sget)
	c := make(chan []byte)
	go func() {
		var d zx.Dir
		f, err := t.walk(rid)
		if f == nil && err == nil {	// Ctl
			d = ctldir.Dup()
		} else if err == nil {
			d, err = t.statf(f, rid)
		}
		if err == nil && !t.NoPermCheck {
			if !d.CanRead(t.ai) {
				err = fmt.Errorf("%s: %s", rid, dbg.ErrPerm)
			}
		}
		if err == nil && pred != "" {
			err = t.match(d, err, rid, pred)
		}
		if err == nil {
			if d["path"] == "/Ctl" {
				err = t.getCtl(off, count, c)
			} else if d["type"] != "d" {
				if gf, ok := f.(Getter); ok {
					err = gf.Get(off, count, c)
				}
			} else {
				err = t.getdir(f, d, off, count, c)
			}
		}
		cs.End(err != nil)
		if err != nil {
			t.dprintf("get %s: %s\n", rid, err)
		} else {
			t.dprintf("get %s: ok\n", rid)
		}
		close(c, err)
	}()
	return c
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:41,代碼來源:vfs.go

示例15: DbFmt

// Print d in DB format
func DbFmt(d zx.Dir) string {
	var b bytes.Buffer

	fmt.Fprintf(&b, "%-14s", d["path"])
	typ := d["type"]
	if typ == "" {
		fmt.Fprintf(&b, " -")
	} else {
		fmt.Fprintf(&b, " %s", typ)
	}
	if d["rm"] != "" {
		fmt.Fprintf(&b, " GONE")
	} else {
		fmt.Fprintf(&b, " 0%o", d.Mode())
	}
	uid := nouid(d["Uid"])
	gid := nouid(d["Gid"])
	wuid := nouid(d["Wuid"])
	fmt.Fprintf(&b, " %-8s %-8s %-8s", uid, gid, wuid)
	fmt.Fprintf(&b, " %8d", d.Int64("size"))
	if d["type"] != "d" {
		fmt.Fprintf(&b, " %d", d.Uint64("mtime"))
	}
	if d["err"] != "" {
		fmt.Fprintf(&b, " %s", d["err"])
	}
	return b.String()
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:29,代碼來源:cmp.go


注:本文中的clive/zx.Dir類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。