From 914c832b87af91884e6919ae70e52c1fe4c1ad4e Mon Sep 17 00:00:00 2001 From: Greg Soltis Date: Mon, 8 May 2023 14:47:37 -0700 Subject: [PATCH 1/2] Drop go implementation of recursive copy --- cli/internal/fs/copy_file.go | 6 +-- ...cursive_copy_rust.go => recursive_copy.go} | 0 cli/internal/fs/recursive_copy_go.go | 38 ------------------- 3 files changed, 3 insertions(+), 41 deletions(-) rename cli/internal/fs/{recursive_copy_rust.go => recursive_copy.go} (100%) delete mode 100644 cli/internal/fs/recursive_copy_go.go diff --git a/cli/internal/fs/copy_file.go b/cli/internal/fs/copy_file.go index 9b9617659035c..f0ce57bc64d64 100644 --- a/cli/internal/fs/copy_file.go +++ b/cli/internal/fs/copy_file.go @@ -14,14 +14,14 @@ import ( // It's implemented over github.com/karrick/godirwalk but the provided interface doesn't use that // to make it a little easier to handle. func Walk(rootPath string, callback func(name string, isDir bool) error) error { - return WalkMode(rootPath, func(name string, isDir bool, mode os.FileMode) error { + return walkMode(rootPath, func(name string, isDir bool, mode os.FileMode) error { return callback(name, isDir) }) } -// WalkMode is like Walk but the callback receives an additional type specifying the file mode type. +// walkMode is like Walk but the callback receives an additional type specifying the file mode type. // N.B. This only includes the bits of the mode that determine the mode type, not the permissions. -func WalkMode(rootPath string, callback func(name string, isDir bool, mode os.FileMode) error) error { +func walkMode(rootPath string, callback func(name string, isDir bool, mode os.FileMode) error) error { return godirwalk.Walk(rootPath, &godirwalk.Options{ Callback: func(name string, info *godirwalk.Dirent) error { // currently we support symlinked files, but not symlinked directories: diff --git a/cli/internal/fs/recursive_copy_rust.go b/cli/internal/fs/recursive_copy.go similarity index 100% rename from cli/internal/fs/recursive_copy_rust.go rename to cli/internal/fs/recursive_copy.go diff --git a/cli/internal/fs/recursive_copy_go.go b/cli/internal/fs/recursive_copy_go.go deleted file mode 100644 index baa60d2a8387c..0000000000000 --- a/cli/internal/fs/recursive_copy_go.go +++ /dev/null @@ -1,38 +0,0 @@ -//go:build go || !rust -// +build go !rust - -package fs - -import ( - "os" - "path/filepath" - - "github.com/vercel/turbo/cli/internal/turbopath" -) - -// RecursiveCopy copies either a single file or a directory. -func RecursiveCopy(from turbopath.AbsoluteSystemPath, to turbopath.AbsoluteSystemPath) error { - // Verified all callers are passing in absolute paths for from (and to) - statedFrom := LstatCachedFile{Path: from} - fromType, err := statedFrom.GetType() - if err != nil { - return err - } - - if fromType.IsDir() { - return WalkMode(statedFrom.Path.ToStringDuringMigration(), func(name string, isDir bool, fileType os.FileMode) error { - dest := filepath.Join(to.ToStringDuringMigration(), name[len(statedFrom.Path.ToString()):]) - // name is absolute, (originates from godirwalk) - src := LstatCachedFile{Path: UnsafeToAbsoluteSystemPath(name), fileType: &fileType} - if isDir { - mode, err := src.GetMode() - if err != nil { - return err - } - return os.MkdirAll(dest, mode) - } - return CopyFile(&src, dest) - }) - } - return CopyFile(&statedFrom, to.ToStringDuringMigration()) -} From ae36eb773ed764449959eed8ff4cdf43915b090d Mon Sep 17 00:00:00 2001 From: Greg Soltis Date: Mon, 8 May 2023 16:05:11 -0700 Subject: [PATCH 2/2] Re-export WalkMode, it's used on non-mac filewatching backends --- cli/internal/fs/copy_file.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/internal/fs/copy_file.go b/cli/internal/fs/copy_file.go index f0ce57bc64d64..9b9617659035c 100644 --- a/cli/internal/fs/copy_file.go +++ b/cli/internal/fs/copy_file.go @@ -14,14 +14,14 @@ import ( // It's implemented over github.com/karrick/godirwalk but the provided interface doesn't use that // to make it a little easier to handle. func Walk(rootPath string, callback func(name string, isDir bool) error) error { - return walkMode(rootPath, func(name string, isDir bool, mode os.FileMode) error { + return WalkMode(rootPath, func(name string, isDir bool, mode os.FileMode) error { return callback(name, isDir) }) } -// walkMode is like Walk but the callback receives an additional type specifying the file mode type. +// WalkMode is like Walk but the callback receives an additional type specifying the file mode type. // N.B. This only includes the bits of the mode that determine the mode type, not the permissions. -func walkMode(rootPath string, callback func(name string, isDir bool, mode os.FileMode) error) error { +func WalkMode(rootPath string, callback func(name string, isDir bool, mode os.FileMode) error) error { return godirwalk.Walk(rootPath, &godirwalk.Options{ Callback: func(name string, info *godirwalk.Dirent) error { // currently we support symlinked files, but not symlinked directories: