当前位置: 首页>>代码示例>>Golang>>正文


Golang os.FileInfo类代码示例

本文整理汇总了Golang中os.FileInfo的典型用法代码示例。如果您正苦于以下问题:Golang FileInfo类的具体用法?Golang FileInfo怎么用?Golang FileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetHash

// Return the hash for path stored in the xattrs. If the hash is out of date,
// the hash is computed anew, unless `compute` is false in which case nil is
// returned.
func GetHash(path string, info os.FileInfo, compute bool) (mh.Multihash, error) {
	if info.Mode()&os.ModeSymlink != 0 {
		return symlinkHash(path)
	}

	hashTimeStr, err := attrs.Get(path, XattrHashTime)
	if err != nil {
		if compute {
			return HashFile(path, info)
		} else if IsNoData(err) {
			// ignore error
			return nil, nil
		} else {
			return nil, err
		}
	}

	hashTime, err := time.Parse(time.RFC3339Nano, string(hashTimeStr))
	if err != nil {
		return nil, err
	}

	if hashTime != info.ModTime() {
		if compute {
			return HashFile(path, info)
		} else {
			return nil, nil
		}
	}

	return attrs.Get(path, XattrHash)
}
开发者ID:mildred,项目名称:doc,代码行数:35,代码来源:hash.go

示例2: shouldRead

func (f *Filesystem) shouldRead(filePath string, fi os.FileInfo) (bool, error) {
	if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
		link, err := filepath.EvalSymlinks(filePath)
		if err != nil {
			jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", filePath, err)
			return false, nil
		}
		linkfi, err := os.Stat(link)
		if err != nil {
			jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
			return false, nil
		}
		if !linkfi.Mode().IsRegular() {
			jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", filePath)
		}
		return false, nil
	}

	if fi.IsDir() {
		if f.avoid(filePath) || isNonProcessablePath(filePath) {
			return false, filepath.SkipDir
		}
		return false, nil
	}

	if isNonProcessablePath(filePath) {
		return false, nil
	}
	return true, nil
}
开发者ID:yanwushuang,项目名称:pango,代码行数:30,代码来源:filesystem.go

示例3: mountVolumes

func (daemon *Daemon) mountVolumes(container *Container) error {
	mounts, err := daemon.setupMounts(container)
	if err != nil {
		return err
	}

	for _, m := range mounts {
		dest, err := container.GetResourcePath(m.Destination)
		if err != nil {
			return err
		}

		var stat os.FileInfo
		stat, err = os.Stat(m.Source)
		if err != nil {
			return err
		}
		if err = fileutils.CreateIfNotExists(dest, stat.IsDir()); err != nil {
			return err
		}

		opts := "rbind,ro"
		if m.Writable {
			opts = "rbind,rw"
		}

		if err := mount.Mount(m.Source, dest, "bind", opts); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:RockaLabs,项目名称:docker,代码行数:33,代码来源:container_unix.go

示例4: checkFile

func checkFile(f os.FileInfo) bool {
	if f.Mode().IsRegular() {
		return true
	}

	return false
}
开发者ID:dbulkow,项目名称:ansible_webui,代码行数:7,代码来源:ansible.go

示例5: getReaderSize

// getReaderSize gets the size of the underlying reader, if possible.
func getReaderSize(reader io.Reader) (size int64, err error) {
	size = -1
	if reader != nil {
		switch v := reader.(type) {
		case *bytes.Buffer:
			size = int64(v.Len())
		case *bytes.Reader:
			size = int64(v.Len())
		case *strings.Reader:
			size = int64(v.Len())
		case *os.File:
			var st os.FileInfo
			st, err = v.Stat()
			if err != nil {
				return 0, err
			}
			size = st.Size()
		case *Object:
			var st ObjectInfo
			st, err = v.Stat()
			if err != nil {
				return 0, err
			}
			size = st.Size
		}
	}
	return size, nil
}
开发者ID:aut0,项目名称:restic,代码行数:29,代码来源:api-put-object.go

示例6: NewCommonFileMap

func NewCommonFileMap(fileName string, fi *os.FileInfo) map[string]interface{} {
	m := newCamliMap(1, "" /* no type yet */)

	lastSlash := strings.LastIndex(fileName, "/")
	baseName := fileName[lastSlash+1:]
	if isValidUtf8(baseName) {
		m["fileName"] = baseName
	} else {
		m["fileNameBytes"] = []uint8(baseName)
	}

	// Common elements (from file-common.txt)
	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:marsch,项目名称:camlistore,代码行数:35,代码来源:schema.go

示例7: writeTarHeader

// writeTarHeader writes tar header for given file, returns error if operation fails
func (t *stiTar) writeTarHeader(tarWriter *tar.Writer, dir string, path string, info os.FileInfo, includeDirInPath bool) error {
	var (
		link string
		err  error
	)
	if info.Mode()&os.ModeSymlink != 0 {
		link, err = os.Readlink(path)
		if err != nil {
			return err
		}
	}
	header, err := tar.FileInfoHeader(info, link)
	if err != nil {
		return err
	}
	prefix := dir
	if includeDirInPath {
		prefix = filepath.Dir(prefix)
	}
	header.Name = filepath.ToSlash(path[1+len(prefix):])
	glog.V(5).Infof("Adding to tar: %s as %s", path, header.Name)
	if err = tarWriter.WriteHeader(header); err != nil {
		return err
	}

	return nil
}
开发者ID:kcbabo,项目名称:origin,代码行数:28,代码来源:tar.go

示例8: parseProvidesRequires

func parseProvidesRequires(fi os.FileInfo, path string, f io.Reader) (provides, requires []string, err error) {
	mt := fi.ModTime()
	depCacheMu.Lock()
	defer depCacheMu.Unlock()
	if ci := depCache[path]; ci.modTime.Equal(mt) {
		return ci.provides, ci.requires, nil
	}

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		l := scanner.Text()
		if !strings.HasPrefix(l, "goog.") {
			continue
		}
		m := provReqRx.FindStringSubmatch(l)
		if m != nil {
			if m[1] == "provide" {
				provides = append(provides, m[2])
			} else {
				requires = append(requires, m[2])
			}
		}
	}
	if err := scanner.Err(); err != nil {
		return nil, nil, err
	}
	depCache[path] = depCacheItem{provides: provides, requires: requires, modTime: mt}
	return provides, requires, nil
}
开发者ID:JayBlaze420,项目名称:camlistore,代码行数:29,代码来源:gendeps.go

示例9: checkHtmlDoWrite

func (p *Page) checkHtmlDoWrite(tplFi, htmlFi os.FileInfo, htmlErr error) bool {
	var doWrite bool
	if p.Config.AutoGenerateHtmlCycleTime <= 0 {
		doWrite = true
	} else {
		if htmlErr != nil {
			doWrite = true
		} else {
			switch {
			case tplFi.ModTime().Unix() >= htmlFi.ModTime().Unix():
				doWrite = true
			case tplFi.ModTime().Unix() >= htmlFi.ModTime().Unix():
				doWrite = true
			case time.Now().Unix()-htmlFi.ModTime().Unix() >= p.Config.AutoGenerateHtmlCycleTime:
				doWrite = true
			default:
				if globalTplCache := p.site.GetTemplateCache("globalTpl"); globalTplCache.ModTime > 0 && globalTplCache.ModTime >= htmlFi.ModTime().Unix() {
					doWrite = true
				}
			}
		}
	}

	return doWrite
}
开发者ID:JessonChan,项目名称:framework,代码行数:25,代码来源:page.go

示例10: handleFile

func handleFile(sourceDirectory string, targetDirectory string,
	file os.FileInfo) {
	fn := filepath.Join(sourceDirectory, file.Name())
	logging.Log.Debug("filename=%s", fn)
	photo := photograph.New()
	err := photo.Load(fn)
	if err != nil {
		logging.Log.Error(err.Error())
	}
	logging.Log.Debug("%d EXIF tags", len(photo.ExifMap))
	for tag, value := range photo.ExifMap {
		fmt.Printf("%s\t%s\n", tag, value)
	}
	logging.Log.Debug("photo=%v", photo.OriginalFileName)
	logging.Log.Debug("targetDir=%v", targetDirectory)
	targetDirectory = getTargetDirectoryNameWithDate(photo.Time,
		targetDirectory)
	err = os.MkdirAll(targetDirectory, 0700)
	if err != nil {
		logging.Log.Error(err.Error())
	}
	s := strings.Replace(file.Name(), "_DSC", "", 1)
	s = strings.Replace(s, "DSC_", "", 1)
	ext := filepath.Ext(s)
	s = strings.Replace(s, ext, "", 1)
	ext = strings.ToLower(ext)
	logging.Log.Debug("ext=%s", ext)
	targetFile := fmt.Sprintf("%s_%s_%s%s", photo.Iso8601(), s,
		"makela_ari", ext)
	targetFile = filepath.Join(targetDirectory, targetFile)
	logging.Log.Debug("targetFile=%s", targetFile)
	ioutil.WriteFile(targetFile, photo.Data, 0600)
}
开发者ID:hauva69,项目名称:photowalk,代码行数:33,代码来源:photowalk.go

示例11: loadMessageFile

// Load a single message file
func loadMessageFile(path string, info os.FileInfo, osError error) error {
	if osError != nil {
		return osError
	}
	if info.IsDir() {
		return nil
	}

	if matched, _ := regexp.MatchString(messageFilePattern, info.Name()); matched {
		if config, error := parseMessagesFile(path); error != nil {
			return error
		} else {
			locale := parseLocaleFromFileName(info.Name())

			// If we have already parsed a message file for this locale, merge both
			if _, exists := messages[locale]; exists {
				messages[locale].Merge(config)
				TRACE.Printf("Successfully merged messages for locale '%s'", locale)
			} else {
				messages[locale] = config
			}

			TRACE.Println("Successfully loaded messages from file", info.Name())
		}
	} else {
		TRACE.Printf("Ignoring file %s because it did not have a valid extension", info.Name())
	}

	return nil
}
开发者ID:revel,项目名称:revel,代码行数:31,代码来源:i18n.go

示例12: NewSerialFile

func NewSerialFile(name, path string, hidden bool, stat os.FileInfo) (File, error) {
	switch mode := stat.Mode(); {
	case mode.IsRegular():
		file, err := os.Open(path)
		if err != nil {
			return nil, err
		}
		return NewReaderFile(name, path, file, stat), nil
	case mode.IsDir():
		// for directories, stat all of the contents first, so we know what files to
		// open when NextFile() is called
		contents, err := ioutil.ReadDir(path)
		if err != nil {
			return nil, err
		}
		return &serialFile{name, path, contents, stat, nil, hidden}, nil
	case mode&os.ModeSymlink != 0:
		target, err := os.Readlink(path)
		if err != nil {
			return nil, err
		}
		return NewLinkFile(name, path, target, stat), nil
	default:
		return nil, fmt.Errorf("Unrecognized file type for %s: %s", name, mode.String())
	}
}
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:26,代码来源:serialfile.go

示例13: includeFolders

func (self *Watcher) includeFolders(path string, info os.FileInfo, err error) error {
	if info.IsDir() {
		log.Println("Including:", path)
		self.watched[path] = contract.NewPackage(path)
	}
	return nil
}
开发者ID:newobject,项目名称:goconvey,代码行数:7,代码来源:watcher.go

示例14: isRegularFile

func isRegularFile(fi os.FileInfo) bool {
	if fi == nil {
		return false
	}

	return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0
}
开发者ID:tharrisone,项目名称:restic,代码行数:7,代码来源:archiver.go

示例15: parseAndStore

// Append the paths to an array in case that they are markdown files.
func (site *Site) parseAndStore(path string, fileInfo os.FileInfo, inputErr error) (err error) {
	if inputErr != nil {
		return inputErr
	}

	slugsPresence := make(map[string]bool)

	if !fileInfo.Mode().IsDir() && strings.HasSuffix(path, ".md") {
		file, err := file.New(path)
		if err != nil {
			return err
		}

		if _, present := slugsPresence[file.Slug]; present {
			return newUniqueSlugError(file.Slug)
		}
		slugsPresence[file.Slug] = true

		// Add the pages or articles to the proper array on the site
		if file.IsPage {
			site.Pages = append(site.Pages, file)
		} else {
			site.Articles = append(site.Articles, file)

			// Just supported on Articles
			if len(file.Tags) > 0 {
				site.AppendUniqueTags(file.Tags)
			}
			site.AppendUniqueCategory(file.Category)
		}
	}
	return
}
开发者ID:repos-blogs-static,项目名称:polo,代码行数:34,代码来源:types.go


注:本文中的os.FileInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。