本文整理汇总了Golang中os.FileInfo.IsSymlink方法的典型用法代码示例。如果您正苦于以下问题:Golang FileInfo.IsSymlink方法的具体用法?Golang FileInfo.IsSymlink怎么用?Golang FileInfo.IsSymlink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.FileInfo
的用法示例。
在下文中一共展示了FileInfo.IsSymlink方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewCommonFileMap
func NewCommonFileMap(fileName string, fi *os.FileInfo) map[string]interface{} {
m := NewCommonFilenameMap(fileName)
// Common elements (from file-common.txt)
if !fi.IsSymlink() {
m["unixPermission"] = fmt.Sprintf("0%o", fi.Permission())
}
if fi.Uid != -1 {
m["unixOwnerId"] = fi.Uid
if user := getUserFromUid(fi.Uid); user != "" {
m["unixOwner"] = user
}
}
if fi.Gid != -1 {
m["unixGroupId"] = fi.Gid
if group := getGroupFromGid(fi.Gid); group != "" {
m["unixGroup"] = group
}
}
if mtime := fi.Mtime_ns; mtime != 0 {
m["unixMtime"] = RFC3339FromNanos(mtime)
}
// Include the ctime too, if it differs.
if ctime := fi.Ctime_ns; ctime != 0 && fi.Mtime_ns != fi.Ctime_ns {
m["unixCtime"] = RFC3339FromNanos(ctime)
}
return m
}
示例2: SetRequestMetaData
func (p *Propolis) SetRequestMetaData(req *http.Request, info *os.FileInfo) {
// file permissions: grant "public-read" if the file grants world read permission
if info.Permission()&s_iroth != 0 {
req.Header.Set("X-Amz-Acl", acl_public)
} else {
req.Header.Set("X-Amz-Acl", acl_private)
}
// user id: store the numeric and symbolic names
user, err := user.LookupId(info.Uid)
if err != nil {
req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d", info.Uid))
} else {
req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d (%s)", info.Uid, user.Username))
}
// group id: just store the numeric id for now until Go supports looking up group names
req.Header.Set("X-Amz-Meta-Gid", fmt.Sprintf("%d", info.Gid))
// store the permissions as an octal number
req.Header.Set("X-Amz-Meta-Mode", fmt.Sprintf("0%o", info.Mode))
// store the modified date in a nice format
sec := info.Mtime_ns / 1e9
ns := info.Mtime_ns % 1e9
date := time.SecondsToLocalTime(sec).String()
if ns == 0 {
req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d (%s)", sec, date))
} else {
req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d.%09d (%s)", sec, ns, date))
}
// set the content-type by looking up the MIME type
mimetype := default_mime_type
switch {
case info.IsDirectory():
mimetype = directory_mime_type
case info.IsSymlink():
mimetype = symlink_mime_type
default:
if dot := strings.LastIndex(info.Name, "."); dot >= 0 && dot+1 < len(info.Name) {
extension := strings.ToLower(info.Name[dot:])
if kind := mime.TypeByExtension(extension); kind != "" {
mimetype = kind
}
}
}
req.Header.Set("Content-Type", mimetype)
}
示例3: symbol
func symbol(f *os.FileInfo) (s string) {
switch {
case f.IsDirectory():
s = "/"
case f.IsFifo():
s = "|"
case f.IsSocket():
s = "="
case f.IsSymlink():
target, err := os.Readlink(f.Name)
Errhandler(err)
s = " -> " + target
}
return
}
示例4: getEntryTypeString
func getEntryTypeString(e *os.FileInfo) string {
if e.IsDirectory() {
return "/"
} else if e.IsBlock() {
return "<>"
} else if e.IsFifo() {
return ">>"
} else if e.IsSymlink() {
return "@"
} else if e.IsSocket() {
return "&"
} else if e.IsRegular() && (e.Mode&0001 == 0001) {
return "*"
}
return ""
}