本文整理匯總了Golang中clive/zx.Path函數的典型用法代碼示例。如果您正苦於以下問題:Golang Path函數的具體用法?Golang Path怎麽用?Golang Path使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Path函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Mkdirs
func Mkdirs(t Fataler, dirs ...string) {
if len(dirs) == 0 {
t.Fatalf("not enough dirs")
}
for _, d := range dirs {
for _, dp := range MkdirPaths {
printf("mkdir %s\n", dp)
p := zx.Path(d, dp)
if err := os.Mkdir(p, 0750); err != nil {
t.Fatalf("mkdir %s: %s", p, err)
}
fi, err := os.Stat(p)
if err != nil {
t.Fatalf("didn't stat: %s", err)
}
if !fi.IsDir() {
t.Fatalf("didn't create a dir")
}
if fi.Mode().String() != "drwxr-x---" {
t.Fatalf("bad dir mode")
}
}
for _, dp := range BadMkdirPaths {
printf("mkdir %s\n", dp)
p := zx.Path(d, dp)
if err := os.Mkdir(p, 0750); err == nil {
t.Fatalf("mkdir %s: didn't fail")
}
}
}
}
示例2: diff
func diff(rc chan<- string, fn string, mtime bool, dirs ...string) {
d0 := dirs[0]
dirs = dirs[1:]
for _, di := range dirs {
p0 := zx.Path(d0, fn)
pi := zx.Path(di, fn)
s := diff1(p0, pi, fn != "/", mtime)
if s != "" {
rc <- fmt.Sprintf("%s: chg %s %s", di, fn, s)
}
c0 := Children(p0)
c1 := Children(pi)
if len(c0) ==0 && len(c1) == 0 {
continue
}
for _, c := range c0 {
cf := zx.Path(fn, c)
if !member(c, c1) {
rc <- fmt.Sprintf("%s: del %s", di, cf)
continue
}
diff(rc, cf, mtime, d0, di)
}
for _, c := range c1 {
if !member(c, c0) {
cf := zx.Path(fn, c)
rc <- fmt.Sprintf("%s: add %s", di, cf)
}
}
}
}
示例3: canWalkTo
// Walk to the given rid checking out perms when t.ai is not nil.
// Returns also the gid and mode even when no perms are checked.
func (t *Lfs) canWalkTo(rid string, forwhat int) (string, uint64, error) {
if !t.readattrs || rid == "/Ctl" {
return dbg.Usr, 0777, nil
}
noperm := t.NoPermCheck || t.ai == nil
elems := zx.Elems(rid)
fpath := t.path
pgid := ""
var pmode uint64
if len(elems) == 0 {
elems = append(elems, "/")
}
for len(elems) > 0 {
if noperm {
// skip to just the final step
if len(elems) > 1 {
fpath = zx.Path(t.path, path.Dir(rid))
elems = elems[len(elems)-1:]
}
}
pd := zx.Dir{
"name": elems[0],
}
fpath = zx.Path(fpath, elems[0])
elems = elems[1:]
st, err := os.Stat(fpath)
if err != nil {
return "", 0, err
}
mode := st.Mode()
m := int64(mode & 0777)
pd["mode"] = "0" + strconv.FormatInt(m, 8)
t.fileAttrs(fpath, pd)
if !noperm && len(elems) > 0 && !pd.CanWalk(t.ai) {
return "", 0, dbg.ErrPerm
}
if len(elems) == 0 {
pgid = pd["Gid"]
pmode = uint64(pd.Int("mode"))
}
if !noperm && len(elems) == 0 && forwhat != 0 {
if !pd.Can(t.ai, forwhat) {
return "", 0, dbg.ErrPerm
}
}
}
if pgid == "" {
pgid = dbg.Usr
}
if pmode == 0 {
pmode = 0775
}
return pgid, pmode, nil
}
示例4: moved
// make sure paths are ok in children after a move
func (f *mFile) moved() {
f.mlk.Lock()
fpath := f.d["path"]
fspath := f.d["spath"]
f.mlk.Unlock()
f.clk.Lock()
defer f.clk.Unlock()
for _, cs := range f.child {
cs.mlk.Lock()
cs.d["path"] = zx.Path(fpath, cs.name)
cs.d["spath"] = zx.Path(fspath, cs.name)
cs.mlk.Unlock()
cs.moved()
}
}
示例5: All
func All(t Fataler, dirs ...string) {
diffs, err := Diff(WithoutMtime, dirs...)
if err != nil {
t.Fatalf("diff errors")
}
if len(diffs) != 0 {
t.Fatalf("initial diffs")
}
Stats(t, dirs...)
Gets(t, dirs...)
AsAFile(t, dirs...)
Puts(t, dirs...)
Mkdirs(t, dirs...)
Wstats(t, dirs...)
Removes(t, dirs...)
for _, d := range dirs {
os.Remove(zx.Path(d, "/foo"))
}
diffs, err = Diff(WithoutMtime, dirs...)
if err != nil {
t.Fatalf("diff errors")
}
for _, d := range diffs {
printf("diff %s\n", d)
}
if len(diffs) != 0 {
t.Fatalf("final diffs")
}
}
示例6: Wstats
func Wstats(t Fataler, dirs ...string) {
if len(dirs) == 0 {
t.Fatalf("not enough dirs")
}
for _, d := range dirs {
for _, dp := range WstatTests {
p := zx.Path(d, dp.Path)
printf("wstat %s %o %d\n", dp.Path, os.FileMode(dp.Mode)&0777, dp.Mtime)
if err := os.Chmod(p, dp.Mode); err != nil {
if dp.Fails {
continue
}
t.Fatalf("chmod: %s", err)
}
if dp.Fails {
t.Fatalf("wstat didn't fail")
}
mt := time.Unix(dp.Mtime, 0)
if err := os.Chtimes(p, mt, mt); err != nil {
t.Fatalf("chtime: %s", err)
}
fi, err := os.Stat(p)
if err != nil {
t.Fatalf("stat: %s", err)
}
if uint(fi.Mode())&0777 != uint(dp.Mode) {
t.Fatalf("wrong mode")
}
if fi.ModTime().Unix() != dp.Mtime {
t.Fatalf("wrong mtime")
}
}
}
}
示例7: Puts
func Puts(t Fataler, dirs ...string) {
if len(dirs) == 0 {
t.Fatalf("not enough dirs")
}
for _, d := range dirs {
nn := 0
for _, pt := range PutTests {
printf("put %s\n", pt.Path)
p := zx.Path(d, pt.Path)
// 1. use create
fd, err := os.Create(p)
if err != nil && !pt.Fails {
t.Fatalf("create: %s", err)
}
if pt.Fails && err == nil {
t.Fatalf("create did not fail")
}
if pt.Fails {
continue
}
nn++
var buf bytes.Buffer
for i := 0; i < 1000*nn; i++ {
fmt.Fprintf(fd, "hi %s %d\n", pt.Path, i)
fmt.Fprintf(&buf, "hi %s %d\n", pt.Path, i)
}
fd.Close()
printf("%s: %d bytes\n", pt.Path, buf.Len())
dat, err := ioutil.ReadFile(p)
if err != nil {
t.Fatalf("read: %s", err)
}
if bytes.Compare(buf.Bytes(), dat) != 0 {
t.Fatalf("didn't put the bytes")
}
// 2. use openfile with truncate
fd, err = os.OpenFile(p, os.O_TRUNC|os.O_RDWR, 0644)
if err != nil {
t.Fatalf("read: %s", err)
}
for i := 0; i < 1000*nn; i++ {
fmt.Fprintf(fd, "hi %s %d\n", pt.Path, i)
}
fd.Close()
dat, err = ioutil.ReadFile(p)
if err != nil {
t.Fatalf("read: %s", err)
}
if bytes.Compare(buf.Bytes(), dat) != 0 {
t.Fatalf("didn't put the bytes")
}
}
}
}
示例8: walk
// Walk to rid, and return it r/wlocked (unless there's an error) with at least its meta updated.
func (fs *Cfs) walk(rid string, isrlock bool) (f *cFile, left []string, e error) {
fs.dprintf("walk %s...\n", rid)
els := zx.Elems(rid)
left = els
defer func() {
if e != nil {
fs.dprintf("walkerr %s left %v\n", rid, left)
} else {
fs.dprintf("walked %s left %v\n", rid, left)
}
if e == nil && len(left) > 0 {
panic("cfs walk: left and no error")
}
}()
path := "/"
for {
isr := len(els) > 0 || isrlock
nf, err := fs.cwalk(path, isr)
if err != nil {
return f, left, err
}
left = els
f = nf
if len(els) > 0 {
path = zx.Path(path, els[0])
els = els[1:]
}
if len(left) == 0 {
if err := f.needMeta(isr); err != nil {
// lock has been released
if dbg.IsNotExist(err) {
// discovered in needMeta that the file is gone
// we raced, so try again
f, left, err = fs.walk(rid, isrlock)
}
return f, left, err
}
return f, left, nil
}
if err := f.needData(isr, nil); err != nil {
// lock has been released
if dbg.IsNotExist(err) {
// discovered in needMeta that the file is gone
// we raced, so try again
f, left, err = fs.walk(rid, isrlock)
}
return f, left, err
}
if !fs.NoPermCheck && !f.d.CanWalk(fs.ai) {
f.unlockc(isr)
return f, left, fmt.Errorf("%s: %s", f, dbg.ErrPerm)
}
f.unlockc(isr)
}
}
示例9: main
func main() {
defer dbg.Exits("")
os.Args[0] = "zxdump"
dfltdump := zx.Path(dbg.Home, "dump")
opts.NewFlag("s", "don't dump right now, wait until next at 5am", &Skip)
opts.NewFlag("1", "dump once and exit", &Once)
opts.NewFlag("v", "verbose", &Verbose)
opts.NewFlag("D", "debug", &Debug)
opts.NewFlag("x", "expr: files excluded (.*, tmp.* if none given); tmp always excluded.", &Xcludes)
Dump = dfltdump
opts.NewFlag("d", "dir: where to keep the dump, or empty if none", &Dump)
args, err := opts.Parse(os.Args)
if err != nil {
dbg.Warn("%s", err)
opts.Usage()
dbg.Exits(err)
}
if len(Xcludes) == 0 {
Xcludes = []string{".*", "tmp.*", "*.tmp"}
}
Xcludes = append(Xcludes, "tmp")
if len(args) == 0 {
dbg.Warn("arguments missing")
opts.Usage()
dbg.Exits("usage")
}
if Skip && Once {
dbg.Fatal("can't skip the current dump and dump once now")
}
nt := 0
ec := make(chan bool)
for i := 0; i < len(args); i++ {
al := strings.SplitN(args[i], "!", 2)
if len(al) == 1 {
al = append(al, al[0])
al[0] = path.Base(al[0])
}
t, err := lfs.New(al[0], al[1], lfs.RO)
if err != nil {
dbg.Warn("%s: %s", al[0], err)
continue
}
t.ReadAttrs(true)
nt++
go dump(Dump, t, ec)
}
if nt == 0 {
dbg.Fatal("no trees to dump")
}
for nt > 0 {
<-ec
nt--
}
}
示例10: Removes
func Removes(t Fataler, dirs ...string) {
if len(dirs) == 0 {
t.Fatalf("not enough dirs")
}
for _, d := range dirs {
for _, dp := range RemovePaths {
printf("remove %s\n", dp)
p := zx.Path(d, dp)
if err := os.Remove(p); err != nil {
t.Fatalf("rm %s: %s", p, err)
}
}
for _, dp := range BadRemovePaths {
printf("remove %s\n", dp)
p := zx.Path(d, dp)
if err := os.Remove(p); err == nil {
t.Fatalf("rm %s: did not fail", p)
}
}
}
}
示例11: getdir
func (t *Fs) getdir(f File, d zx.Dir, off, count int64, c chan<- []byte) error {
gf, ok := f.(Walker)
if !ok {
return nil
}
ns, err := gf.Getdir()
if err != nil {
return err
}
sort.Sort(sort.StringSlice(ns))
if d["name"] == "/" {
ns = append([]string{"Ctl"}, ns...)
}
Dloop: for _, n := range ns {
if n == "" {
err = fmt.Errorf("%s: empty name in getdir", d["path"], n)
app.Warn("fs bug: %s", err)
return err
}
if off > 0 {
off--
continue
}
switch count {
case zx.All:
break
case 0:
break Dloop
default:
count--
}
if d["name"]=="/" && n == "Ctl" {
cd := ctldir.Dup()
cd["tpath"] = t.path
cd.Send(c)
continue
}
cf, err := gf.Walk(n)
if err != nil {
return err
}
cp := zx.Path(d["path"], n)
cd, err := t.statf(cf, cp)
if err != nil {
return err
}
t.Dprintf("getdir %s: %s\n", gf, cf)
if _, err := cd.Send(c); err != nil {
return err
}
}
return nil
}
示例12: newDumpDir
func newDumpDir(dir, dfpath string, rf zx.File, ds []zx.Dir, dhash []string) error {
if len(dhash) != 2*len(ds) {
panic("newDumpDir: dhash length bug")
}
dprintf("create %s\t%s\n", dfpath, rf.D["path"])
if err := os.MkdirAll(dfpath, 0750); err != nil {
return err
}
var err error
for i := 0; i < len(ds); i++ {
cname := dhash[2*i]
if cname == "" {
continue // entry had errors
}
if cname != ds[i]["name"] {
panic("newDumpDir: bad entry")
}
cdfpath := zx.Path(dir, dhash[2*i+1])
cpath := zx.Path(dfpath, cname)
dprintf("link %s\t<- %s\n", cdfpath, cpath)
var e error
e = os.Symlink(cdfpath, cpath)
// TODO: save user attributes from ds[i] for cname at dfpath/.#zx
if err == nil && e != nil {
err = e
}
if e == nil {
saveAttrs(dfpath, ds[i])
}
}
mt := rf.D.Time("mtime")
os.Chtimes(dfpath, mt, mt)
mode := rf.D.Int("mode")
if mode != 0 {
// uncomment to set dir modes -w
// mode = mode &^ 0222
os.Chmod(dfpath, os.FileMode(mode))
}
return err
}
示例13: Gets
func Gets(t Fataler, dirs ...string) {
if len(dirs) == 0 {
t.Fatalf("not enough dirs")
}
for _, d := range dirs {
for _, fp := range GetFPaths {
p := zx.Path(d, fp)
dat, err := ioutil.ReadFile(p)
if err != nil {
t.Fatalf("get %s: %s", p, err)
}
printf("got %d bytes \n\n", len(dat))
if string(dat) != string(FileData[fp]) {
printf("got <%s>\nexpected<%s>\n",
string(dat), string(FileData[fp]))
t.Fatalf("%s: bad data", p)
}
}
for _, dp := range GetDPaths {
printf("getall %s\n", dp)
p := zx.Path(d, dp)
cs := Children(p)
printf("children `%s`\n", strings.Join(cs, " "))
if strings.Join(cs, " ") != GetDOuts[dp] {
t.Logf("got %s", strings.Join(cs, " "))
t.Fatalf("bad dir data for %s", dp)
}
}
for _, fp := range BadPaths {
p := zx.Path(d, fp)
_, err := ioutil.ReadFile(p)
if err == nil {
t.Fatalf("%s did not fail", fp)
}
}
}
}
示例14: stat
func (t *Lfs) stat(rid string) (zx.Dir, error) {
rid, err := zx.AbsPath(rid)
if err != nil {
return nil, err
}
if rid == "/Ctl" {
d := ctldir.Dup()
d["tpath"] = t.path
return d, nil
}
path := zx.Path(t.path, rid)
st, err := os.Stat(path)
if err != nil {
return nil, err
}
nd := 0
sum := ""
if st.IsDir() {
nd, sum = dirsz(path)
if rid == "/" {
nd++
}
}
d := zx.NewDir(st, nd)
if t.readattrs {
t.fileAttrs(path, d)
}
if sum != "" {
d["Sum"] = sum
}
d["tpath"] = t.path
d["path"] = rid
d["spath"] = rid
d["proto"] = "lfs"
if rid == "/" {
d["name"] = "/"
}
if d["Uid"] == "" {
d["Uid"] = dbg.Usr
}
if d["Gid"] == "" {
d["Gid"] = dbg.Usr
}
if d["Wuid"] == "" {
d["Wuid"] = dbg.Usr
}
return d, nil
}
示例15: 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
}