本文整理汇总了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
}
示例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 ""
}
示例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
}
示例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
}
示例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
}
示例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
}
}