示例#1
0
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
0
文件: save.go 项目: maxamillion/godep
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())
}
示例#3
0
文件: remote.go 项目: iwat/sftpsync
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
}