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


Golang Fs.Stat方法代码示例

本文整理汇总了Golang中github.com/spf13/afero.Fs.Stat方法的典型用法代码示例。如果您正苦于以下问题:Golang Fs.Stat方法的具体用法?Golang Fs.Stat怎么用?Golang Fs.Stat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/spf13/afero.Fs的用法示例。


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

示例1: IsDir

func IsDir(path string, fs afero.Fs) (bool, error) {
	fi, err := fs.Stat(path)
	if err != nil {
		return false, err
	}
	return fi.IsDir(), nil
}
开发者ID:jempe,项目名称:hugo,代码行数:7,代码来源:path.go

示例2: FindArchetype

// FindArchetype takes a given kind/archetype of content and returns an output
// path for that archetype.  If no archetype is found, an empty string is
// returned.
func FindArchetype(fs afero.Fs, kind string) (outpath string) {
	search := []string{helpers.AbsPathify(viper.GetString("archetypeDir"))}

	if viper.GetString("theme") != "" {
		themeDir := filepath.Join(helpers.AbsPathify(viper.GetString("themesDir")+"/"+viper.GetString("theme")), "/archetypes/")
		if _, err := fs.Stat(themeDir); os.IsNotExist(err) {
			jww.ERROR.Printf("Unable to find archetypes directory for theme %q at %q", viper.GetString("theme"), themeDir)
		} else {
			search = append(search, themeDir)
		}
	}

	for _, x := range search {
		// If the new content isn't in a subdirectory, kind == "".
		// Therefore it should be excluded otherwise `is a directory`
		// error will occur. github.com/spf13/hugo/issues/411
		var pathsToCheck []string

		if kind == "" {
			pathsToCheck = []string{"default.md", "default"}
		} else {
			pathsToCheck = []string{kind + ".md", kind, "default.md", "default"}
		}
		for _, p := range pathsToCheck {
			curpath := filepath.Join(x, p)
			jww.DEBUG.Println("checking", curpath, "for archetypes")
			if exists, _ := helpers.Exists(curpath, fs); exists {
				jww.INFO.Println("curpath: " + curpath)
				return curpath
			}
		}
	}

	return ""
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:38,代码来源:content.go

示例3: lstatIfOs

// Code copied from Afero's path.go
// if the filesystem is OsFs use Lstat, else use fs.Stat
func lstatIfOs(fs afero.Fs, path string) (info os.FileInfo, err error) {
	_, ok := fs.(*afero.OsFs)
	if ok {
		info, err = os.Lstat(path)
	} else {
		info, err = fs.Stat(path)
	}
	return
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:11,代码来源:path.go

示例4: DirExists

// Check if Exists && is Directory
func DirExists(path string, fs afero.Fs) (bool, error) {
	fi, err := fs.Stat(path)
	if err == nil && fi.IsDir() {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}
开发者ID:jempe,项目名称:hugo,代码行数:11,代码来源:path.go

示例5: Exists

// Check if File / Directory Exists
func Exists(path string, fs afero.Fs) (bool, error) {
	_, err := fs.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}
开发者ID:jempe,项目名称:hugo,代码行数:11,代码来源:path.go

示例6: IsEmpty

func IsEmpty(path string, fs afero.Fs) (bool, error) {
	if b, _ := Exists(path, fs); !b {
		return false, fmt.Errorf("%q path does not exist", path)
	}
	fi, err := fs.Stat(path)
	if err != nil {
		return false, err
	}
	if fi.IsDir() {
		f, err := os.Open(path)
		// FIX: Resource leak - f.close() should be called here by defer or is missed
		// if the err != nil branch is taken.
		defer f.Close()
		if err != nil {
			return false, err
		}
		list, err := f.Readdir(-1)
		// f.Close() - see bug fix above
		return len(list) == 0, nil
	} else {
		return fi.Size() == 0, nil
	}
}
开发者ID:jempe,项目名称:hugo,代码行数:23,代码来源:path.go


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