From 91c95a711ee26537ad80b6a4fcde1080aa59a82c Mon Sep 17 00:00:00 2001 From: Luke Kingland <58986931+lkingland@users.noreply.github.com> Date: Wed, 22 Feb 2023 05:40:27 +0900 Subject: [PATCH] fix: repo add skips root (#1577) --- pkg/filesystem/filesystem.go | 16 ++++++---------- pkg/functions/repository.go | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/filesystem/filesystem.go b/pkg/filesystem/filesystem.go index aa76a2ba..d43aad75 100644 --- a/pkg/filesystem/filesystem.go +++ b/pkg/filesystem/filesystem.go @@ -252,18 +252,14 @@ func (m maskingFS) Readlink(link string) (string, error) { // CopyFromFS copies files from the `src` dir on the accessor Filesystem to local filesystem into `dest` dir. // The src path uses slashes as their separator. // The dest path uses OS specific separator. -func CopyFromFS(src, dest string, accessor Filesystem) (err error) { - - return fs.WalkDir(accessor, src, func(path string, de fs.DirEntry, err error) error { +func CopyFromFS(root, dest string, fsys Filesystem) (err error) { + // Walks the filesystem rooted at root. + return fs.WalkDir(fsys, root, func(path string, de fs.DirEntry, err error) error { if err != nil { return err } - if path == src { - return nil - } - - p, err := filepath.Rel(filepath.FromSlash(src), filepath.FromSlash(path)) + p, err := filepath.Rel(filepath.FromSlash(root), filepath.FromSlash(path)) if err != nil { return err } @@ -280,7 +276,7 @@ func CopyFromFS(src, dest string, accessor Filesystem) (err error) { return os.MkdirAll(dest, 0755) case de.Type()&fs.ModeSymlink != 0: var symlinkTarget string - symlinkTarget, err = accessor.Readlink(path) + symlinkTarget, err = fsys.Readlink(path) if err != nil { return err } @@ -296,7 +292,7 @@ func CopyFromFS(src, dest string, accessor Filesystem) (err error) { } defer destFile.Close() - srcFile, err := accessor.Open(path) + srcFile, err := fsys.Open(path) if err != nil { return err } diff --git a/pkg/functions/repository.go b/pkg/functions/repository.go index eb15cf96..559e3f22 100644 --- a/pkg/functions/repository.go +++ b/pkg/functions/repository.go @@ -498,7 +498,7 @@ func (r *Repository) Runtime(name string) (runtime Runtime, err error) { } // Write all files in the repository to the given path. -func (r *Repository) Write(path string) (err error) { +func (r *Repository) Write(dest string) (err error) { if r.fs == nil { return errors.New("the write operation is not supported on this repo") } @@ -533,7 +533,7 @@ func (r *Repository) Write(path string) (err error) { } fs = filesystem.NewBillyFilesystem(wt.Filesystem) } - return filesystem.CopyFromFS(".", path, fs) + return filesystem.CopyFromFS(".", dest, fs) } // URL attempts to read the remote git origin URL of the repository. Best