Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ func (d *DepDownloader) Download(opts *DownloadOptions) error {

localPath := opts.LocalPath
cacheFullPath := opts.CachePath
if ok, err := features.Enabled(features.SupportNewStorage); err == nil && !ok && opts.EnableCache {
if ok, err := features.Enabled(features.SupportNewStorage); err == nil &&
!ok &&
opts.EnableCache &&
utils.DirExists(filepath.Join(localPath, constants.KCL_MOD)) {
if utils.DirExists(cacheFullPath) &&
// If the version in modspec is empty, meanings the latest version is needed.
// The latest version should be requested first and the cache should be updated.
Expand Down
33 changes: 33 additions & 0 deletions pkg/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,40 @@ func testGitDownloader(t *testing.T) {
assert.Equal(t, utils.DirExists(filepath.Join(path_git, "git", "src", gitHash, "kcl.mod")), true)
}

func testDepDownloader(t *testing.T) {
path_git := getTestDir("test_dep_downloader")
if err := os.MkdirAll(path_git, os.ModePerm); err != nil {
t.Fatal(err)
}

defer func() {
_ = os.RemoveAll(path_git)
}()
dep := NewOciDownloader("linux/amd64")
err := dep.Download(&DownloadOptions{
LocalPath: path_git,
CachePath: path_git,
EnableCache: true,
Source: Source{
ModSpec: &ModSpec{
Name: "k8s",
Version: "1.28.1",
},
Oci: &Oci{
Reg: "ghcr.io",
Repo: "kcl-lang/k8s",
},
},
})
assert.Equal(t, err, nil)
existFile, err := utils.Exists(path_git + "/kcl.mod")
assert.Equal(t, err, nil)
assert.Equal(t, existFile, true)
}

// go test -timeout 30s -run ^TestWithGlobalLock$ kcl-lang.io/kpm/pkg/downloader -v
func TestWithGlobalLock(t *testing.T) {
test.RunTestWithGlobalLock(t, "TestOciDownloader", testOciDownloader)
test.RunTestWithGlobalLock(t, "TestGitDownloader", testGitDownloader)
test.RunTestWithGlobalLock(t, "TestDepDownloader", testDepDownloader)
}
Loading