本文整理匯總了Golang中clive/zx.Dir.Can方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dir.Can方法的具體用法?Golang Dir.Can怎麽用?Golang Dir.Can使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類clive/zx.Dir
的用法示例。
在下文中一共展示了Dir.Can方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}