10 // copyDir copies the src directory contents into dst. Both directories
11 // should already exist.
13 // If ignoreDot is set to true, then dot-prefixed files/folders are ignored.
14 func copyDir(ctx context.Context, dst string, src string, ignoreDot bool) error {
15 src, err := filepath.EvalSymlinks(src)
20 walkFn := func(path string, info os.FileInfo, err error) error {
28 if ignoreDot && strings.HasPrefix(filepath.Base(path), ".") {
31 return filepath.SkipDir
37 // The "path" has the src prefixed to it. We need to join our
38 // destination with the path without the src on it.
39 dstPath := filepath.Join(dst, path[len(src):])
41 // If we have a directory, make that subdirectory, then continue
44 if path == filepath.Join(src, dst) {
45 // dst is in src; don't walk it.
49 if err := os.MkdirAll(dstPath, 0755); err != nil {
56 // If we have a file, copy the contents.
57 srcF, err := os.Open(path)
63 dstF, err := os.Create(dstPath)
69 if _, err := Copy(ctx, dstF, srcF); err != nil {
74 return os.Chmod(dstPath, info.Mode())
77 return filepath.Walk(src, walkFn)