本文整理匯總了Golang中github.com/kr/fs.Walker.Stat方法的典型用法代碼示例。如果您正苦於以下問題:Golang Walker.Stat方法的具體用法?Golang Walker.Stat怎麽用?Golang Walker.Stat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/kr/fs.Walker
的用法示例。
在下文中一共展示了Walker.Stat方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: copyPkgFile
func copyPkgFile(vf vcsFiles, dstroot, srcroot string, w *fs.Walker) error {
if w.Err() != nil {
return w.Err()
}
name := w.Stat().Name()
if w.Stat().IsDir() {
if name[0] == '.' || name[0] == '_' || (!saveT && name == "testdata") {
// Skip directories starting with '.' or '_' or
// 'testdata' (last is only skipped if saveT is false)
w.SkipDir()
}
return nil
}
rel, err := filepath.Rel(srcroot, w.Path())
if err != nil { // this should never happen
return err
}
if !saveT && strings.HasSuffix(name, "_test.go") {
if verbose {
log.Printf("save: skipping test file: %s", w.Path())
}
return nil
}
if !vf.Contains(w.Path()) {
if verbose {
log.Printf("save: skipping untracked file: %s", w.Path())
}
return nil
}
return copyFile(filepath.Join(dstroot, rel), w.Path())
}
示例2: BuildRemoteFileList
func BuildRemoteFileList(walker *fs.Walker, basepath string) map[string]file {
output := make(map[string]file)
i := 0
for walker.Step() {
if err := walker.Err(); err != nil {
log.Warn("walker error", "err", err)
continue
}
fmt.Print(".")
i++
if i >= 80 {
i = 0
fmt.Println()
}
rel, err := filepath.Rel(basepath, walker.Path())
if err != nil {
log.Warn("could not resolve relative path", "path", walker.Path())
continue
}
if rel == "." {
continue
}
stat := walker.Stat()
file := file{
mode: stat.Mode(),
size: stat.Size(),
mod: stat.ModTime(),
path: walker.Path(),
relPath: rel,
}
output[file.relPath] = file
}
if i > 0 {
fmt.Println()
}
return output
}
示例3: copyPkgFile
func copyPkgFile(dstroot, srcroot string, w *fs.Walker) error {
if w.Err() != nil {
return w.Err()
}
if c := w.Stat().Name()[0]; c == '.' || c == '_' {
// Skip directories using a rule similar to how
// the go tool enumerates packages.
// See $GOROOT/src/cmd/go/main.go:/matchPackagesInFs
w.SkipDir()
}
if w.Stat().IsDir() {
return nil
}
rel, err := filepath.Rel(srcroot, w.Path())
if err != nil { // this should never happen
return err
}
return copyFile(filepath.Join(dstroot, rel), w.Path())
}