mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-19 11:05:53 +02:00
refactor(filesystem): add CopyDir method and optimize Fetch function (#2111)
* refactor(filesystem): add CopyDir method and optimize Fetch function Signed-off-by: yxxhero <aiopsclub@163.com> * fix(state): conditionally prepare charts for local helmfile command Signed-off-by: yxxhero <aiopsclub@163.com> * fix(state): conditionally prepare charts for local helmfile command Signed-off-by: yxxhero <aiopsclub@163.com> * refactor(state): optimize chart path generation and update dependencies Signed-off-by: yxxhero <aiopsclub@163.com> * fix(test): update path in fetch-forl-local-chart test Signed-off-by: yxxhero <aiopsclub@163.com> * add more test cases Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
copyDir "github.com/otiai10/copy"
|
||||
)
|
||||
|
||||
type fileStat struct {
|
||||
@@ -36,6 +38,7 @@ type FileSystem struct {
|
||||
Chdir func(string) error
|
||||
Abs func(string) (string, error)
|
||||
EvalSymlinks func(string) (string, error)
|
||||
CopyDir func(src, dst string) error
|
||||
}
|
||||
|
||||
func DefaultFileSystem() *FileSystem {
|
||||
@@ -55,6 +58,7 @@ func DefaultFileSystem() *FileSystem {
|
||||
dfs.DirectoryExistsAt = dfs.directoryExistsDefault
|
||||
dfs.FileExists = dfs.fileExistsDefault
|
||||
dfs.Abs = dfs.absDefault
|
||||
dfs.CopyDir = dfs.copyDirDefault
|
||||
return &dfs
|
||||
}
|
||||
|
||||
@@ -100,6 +104,9 @@ func FromFileSystem(params FileSystem) *FileSystem {
|
||||
if params.Dir != nil {
|
||||
dfs.Dir = params.Dir
|
||||
}
|
||||
if params.CopyDir != nil {
|
||||
dfs.CopyDir = params.CopyDir
|
||||
}
|
||||
return dfs
|
||||
}
|
||||
|
||||
@@ -180,3 +187,8 @@ func (filesystem *FileSystem) absDefault(path string) (string, error) {
|
||||
}
|
||||
return filepath.Abs(path)
|
||||
}
|
||||
|
||||
// copyDirDefault recursively copies a directory tree, preserving permissions.
|
||||
func (filesystem *FileSystem) copyDirDefault(src string, dst string) error {
|
||||
return copyDir.Copy(src, dst, copyDir.Options{Sync: true})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user