From e085e5e61d66268432751c7970c41f0de4bee5e7 Mon Sep 17 00:00:00 2001 From: peefy Date: Wed, 1 May 2024 01:02:57 +0300 Subject: [PATCH] fix: dep ref symlink Signed-off-by: peefy --- pkg/client/client.go | 43 +++++++++++++++++++-------------------- pkg/client/client_test.go | 38 ++-------------------------------- 2 files changed, 23 insertions(+), 58 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 3b7c6674..c4e73c53 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -7,7 +7,6 @@ import ( "os" "path/filepath" "reflect" - "runtime" "strings" "github.com/BurntSushi/toml" @@ -836,10 +835,10 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (* // Creating symbolic links in a global cache is not an optimal solution. // This allows kclvm to locate the package by default. // This feature is unstable and will be removed soon. - err = createDepRef(dep.LocalFullPath, filepath.Join(filepath.Dir(localPath), dep.Name)) - if err != nil { - return nil, err - } + // err = createDepRef(dep.LocalFullPath, filepath.Join(filepath.Dir(localPath), dep.Name)) + // if err != nil { + // return nil, err + // } dep.FullName = dep.GenDepFullName() // If the dependency is from git commit, the version is the commit id. // If the dependency is from git tag, the version is the tag. @@ -879,10 +878,10 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (* // Creating symbolic links in a global cache is not an optimal solution. // This allows kclvm to locate the package by default. // This feature is unstable and will be removed soon. - err = createDepRef(dep.LocalFullPath, filepath.Join(filepath.Dir(localPath), dep.Name)) - if err != nil { - return nil, err - } + // err = createDepRef(dep.LocalFullPath, filepath.Join(filepath.Dir(localPath), dep.Name)) + // if err != nil { + // return nil, err + // } } if dep.Source.Local != nil { @@ -1513,16 +1512,16 @@ func check(dep pkg.Dependency, newDepPath string) bool { // createDepRef will create a dependency reference for the dependency saved on the local filesystem. // On the unix-like system, it will create a symbolic link. // On the windows system, it will create a junction. -func createDepRef(depName, refName string) error { - if runtime.GOOS == "windows" { - // 'go-getter' continuously occupies files in '.git', causing the copy operation to fail - opt := copy.Options{ - Skip: func(srcinfo os.FileInfo, src, dest string) (bool, error) { - return filepath.Base(src) == constants.GitPathSuffix, nil - }, - } - return copy.Copy(depName, refName, opt) - } else { - return utils.CreateSymlink(depName, refName) - } -} +// func createDepRef(depName, refName string) error { +// if runtime.GOOS == "windows" { +// // 'go-getter' continuously occupies files in '.git', causing the copy operation to fail +// opt := copy.Options{ +// Skip: func(srcinfo os.FileInfo, src, dest string) (bool, error) { +// return filepath.Base(src) == constants.GitPathSuffix, nil +// }, +// } +// return copy.Copy(depName, refName, opt) +// } else { +// return utils.CreateSymlink(depName, refName) +// } +// } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 6cfd19a8..0b80ea07 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -90,24 +90,7 @@ func TestDownloadOci(t *testing.T) { assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s_1.27.tar")), false) assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s_1.27")), true) - assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s")), true) - - // Check whether the reference and the dependency have the same hash. - hashDep, err := utils.HashDir(filepath.Join(downloadPath, "k8s_1.27")) - assert.Equal(t, err, nil) - - depRefPath := filepath.Join(downloadPath, "k8s") - info, err := os.Lstat(depRefPath) - assert.Equal(t, err, nil) - - if info.Mode()&os.ModeSymlink != 0 { - depRefPath, err = os.Readlink(depRefPath) - assert.Equal(t, err, nil) - } - - hashRef, err := utils.HashDir(depRefPath) - assert.Equal(t, err, nil) - assert.Equal(t, hashDep, hashRef) + assert.Equal(t, utils.DirExists(filepath.Join(downloadPath, "k8s")), false) } // TestDownloadLatestOci tests the case that the version is empty. @@ -150,24 +133,7 @@ func TestDownloadLatestOci(t *testing.T) { // Check whether the tar downloaded by `kpm add` has been deleted. assert.Equal(t, utils.DirExists(filepath.Join(testPath, "helloworld_0.1.1.tar")), false) - assert.Equal(t, utils.DirExists(filepath.Join(getTestDir("download"), "helloworld")), true) - - // Check whether the reference and the dependency have the same hash. - hashDep, err := utils.HashDir(dep.LocalFullPath) - assert.Equal(t, err, nil) - - depRefPath := filepath.Join(getTestDir("download"), "helloworld") - info, err := os.Lstat(depRefPath) - assert.Equal(t, err, nil) - - if info.Mode()&os.ModeSymlink != 0 { - depRefPath, err = os.Readlink(depRefPath) - assert.Equal(t, err, nil) - } - - hashRef, err := utils.HashDir(depRefPath) - assert.Equal(t, err, nil) - assert.Equal(t, hashDep, hashRef) + assert.Equal(t, utils.DirExists(filepath.Join(getTestDir("download"), "helloworld")), false) } func TestDependencyGraph(t *testing.T) {