當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FileInfo.IsSymlink方法代碼示例

本文整理匯總了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
}
開發者ID:ipeet,項目名稱:camlistore,代碼行數:28,代碼來源:schema.go

示例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)
}
開發者ID:russross,項目名稱:propolis,代碼行數:49,代碼來源:s3.go

示例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
}
開發者ID:Jovlang,項目名稱:goreutils,代碼行數:15,代碼來源:ls.go

示例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 ""
}
開發者ID:akrennmair,項目名稱:gobox,代碼行數:16,代碼來源:ls.go


注:本文中的os.FileInfo.IsSymlink方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。