func dst(name string) (zx.Dir, error) { if strings.Contains(name, ",") { return nil, errors.New("destination can't be a predicate") } d, err := cmd.Stat(name) if zx.IsNotExist(err) { path := cmd.AbsPath(name) ppath := fpath.Dir(path) pd, err := cmd.Stat(ppath) if err != nil { return nil, err } if pd["type"] != "d" { return nil, fmt.Errorf("%s: %s", pd["path"], zx.ErrNotDir) } base := fpath.Base(path) pd["path"] = fpath.Join(pd["path"], base) pd["Upath"] = name pd["Rpath"] = "/" if pd["addr"] != "" { pd["addr"] += "/" + base } return pd, nil } return d, nil }
func (fs *Fs) chkWalk(p string, mkall bool) error { if fs.ai == nil { return nil } els := zx.Elems(p) rp := "/" for len(els) > 0 { d, err := fs.stat(rp, false) rp = fpath.Join(rp, els[0]) if err != nil { if !mkall || !zx.IsNotExist(err) { return err } path := fpath.Join(fs.root, rp) if e := os.Mkdir(path, 0755); e != nil { return err } } if !d.CanWalk(fs.ai) { return fmt.Errorf("%s: %s", d["path"], zx.ErrPerm) } if len(els) == 1 { return nil } els = els[1:] } return nil }
func Stats(t Fataler, fs zx.Fs) { ds := []zx.Dir{} for _, p := range AllFiles { dc := fs.Stat(p) d := <-dc if err := cerror(dc); err != nil { t.Fatalf("stat %s: %s", p, err) } ds = append(ds, d) } for _, d := range ds { Printf("%s\n", d.Fmt()) } Printf("\n") for _, d := range ds { Printf("%s\n", d.LongFmt()) } Printf("\n") for i, d := range ds { s := d.TestFmt() Printf("`%s`,\n", s) if s != stats[i] && !strings.HasPrefix(s, stats[i]) { Printf("not `%s`,\n", stats[i]) t.Fatalf("bad stat") } } Printf("\n") for _, p := range NotThere { dc := fs.Stat(p) d := <-dc if d != nil { t.Fatalf("%s is there", p) } if !zx.IsNotExist(cerror(dc)) { Printf("bad err %v\n", cerror(dc)) } } for i, p := range BadPaths { d, err := zx.Stat(fs, p) if d != nil { Printf("%s\n", d.TestFmt()) } else { Printf("err %s\n", err) } if i == 0 && d["path"] != "/" { t.Fatalf("bad bad path") } if i > 0 && d != nil { t.Fatalf("bad bad path") } } }
func (db *DB) applyDel(c Chg, rdb *DB) error { if c.D["path"] == "/" { return errors.New("won't del /") } fs, ok := db.Fs.(zx.Remover) if !ok { return errors.New("Fs can't remove") } p := fpath.Join(db.rpath, c.D["path"]) db.Dprintf("del %s\n", c.D.Fmt()) err := <-fs.RemoveAll(p) if err != nil && !zx.IsNotExist(err) { return err } c.D["rm"] = "y" err = db.Add(c.D) if zx.IsNotExist(err) { err = nil } if err == nil { rdb.Add(c.D) } return err }