func (ch Chg) applyMeta(lfs zx.RWTree) error { nd := ch.D.UsrAttrs() for _, k := range ignoredPutAttrs { delete(nd, k) } ec := lfs.Wstat(ch.D["path"], nd) return <-ec }
// Make some changes in the test zx tree, another version. // - Remove /2 // - Create /2/n2 // - Truncate /1 func MkZXChgs2(t Fataler, fs zx.RWTree) { if err := <-fs.Remove("/2"); err != nil { t.Fatalf("rm: %s", err) } <-fs.Mkdir("/2", zx.Dir{"mode": "0750"}) if err := <-fs.Mkdir("/2/n2", zx.Dir{"mode": "0750"}); err != nil { t.Fatalf("mkdir: %s", err) } TouchZX(fs, "/2/n2") TouchZX(fs, "/2") if err := <-fs.Wstat("/1", zx.Dir{"size": "50"}); err != nil { t.Fatalf("truncate: %s", err) } TouchZX(fs, "/1") }
// Make some changes in the test zx tree. // - Touch /a/a1 // - Chmod /a/a2 // - Remove /a/b/c /a/b/c/c3 // - Create /a/n /a/n/m /a/n/m/m1 func MkZXChgs(t Fataler, fs zx.RWTree) { TouchZX(fs, "/a/a1") if err := <- fs.Wstat("/a/a2", zx.Dir{"mode": "0750"}); err != nil { t.Fatalf("chmod: %s", err) } if err := <-fs.RemoveAll("/a/b/c"); err != nil { t.Fatalf("rm: %s", err) } <-fs.Mkdir("/a", zx.Dir{"mode": "0750"}) <-fs.Mkdir("/a/n", zx.Dir{"mode": "0750"}) if err := <-fs.Mkdir("/a/n/m", zx.Dir{"mode": "0750"}); err != nil { t.Fatalf("mkdir: %s", err) } err := zx.PutAll(fs, "/a/n/m/m1", zx.Dir{"mode": "0640"}, []byte("a new file\n")) if err != nil { t.Fatalf("new file: %s", err) } TouchZX(fs, "/a/n/m/m1") TouchZX(fs, "/a/n/m") TouchZX(fs, "/a/n") TouchZX(fs, "/a") }
// see if fn has errors (permissions) or not for the given path and 1,2,4 perm. bit. // returns xxxxxxxxxxxx where x is y or n // for ugo and masks 777 770 700 000 // Expected result is always yyyyynynnnnn func ugo(t Fataler, fs zx.RWTree, p string, bit uint, fn func(zx.RWTree) error) string { err := <-fs.Wstat(p, zx.Dir{"mode": "0777"}) if err != nil { t.Fatalf("wstat: %s", err) } defer func() { // so we can later remove it <-fs.Wstat(p, zx.Dir{"mode": "0755"}) }() // /chkd is nemo gid1 usrs := []usr{ usr{who: "uid", ai: &auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true, Gids: map[string]bool{}}}, usr{who: "gid", ai: &auth.Info{Uid: "gid1", SpeaksFor: dbg.Usr, Ok: true, Gids: map[string]bool{}}}, usr{who: "oid", ai: &auth.Info{Uid: "other", SpeaksFor: dbg.Usr, Ok: true, Gids: map[string]bool{}}}, } shift := uint(0) m := uint(0777) out := "" for i := 0; i < 4; i++ { printf("mode %o\n", m) err := <-fs.Wstat(p, zx.Dir{"mode": fmt.Sprintf("0%o", m)}) if err != nil { t.Fatalf("wstat: %s", err) } for _, u := range usrs { if err := fn(authfor(t, fs, u.ai)); err != nil { out += "n" printf("%s can't for %o\n", u.who, m) } else { out += "y" printf("%s can for %o\n", u.who, m) } } m &^= (bit << shift) shift += 3 } return out }
// set a fake mtime that can be predicted. func TouchZX(fs zx.RWTree, path string) error { d := zx.Dir{} d.SetTime("mtime", time.Unix(xt/1e9, xt%1e9)) xt += 1e9 return <-fs.Wstat(path, d) }
func rwstat(t Fataler, fs zx.RWTree, fname string) { <-fs.Wstat(fname, zx.Dir{"mode": "0700", "Foo": "Bar"}) }