From 80505ad4bf6bcaf931b27aa1b5e758ef852f85ae Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 20 Nov 2024 11:08:03 +0800 Subject: [PATCH 1/6] fix: fix 'edge already exists' when kpm run Signed-off-by: zongz --- pkg/client/client.go | 9 ++- pkg/client/client_test.go | 42 ++++++++++++ .../issues/kcl-lang/kcl/issue/1760/README.md | 68 +++++++++++++++++++ .../issues/kcl-lang/kcl/issue/1760/a/kcl.mod | 9 +++ .../kcl-lang/kcl/issue/1760/a/kcl.mod.lock | 29 ++++++++ .../issues/kcl-lang/kcl/issue/1760/a/main.k | 1 + .../issues/kcl-lang/kcl/issue/1760/b/kcl.mod | 7 ++ .../kcl-lang/kcl/issue/1760/b/kcl.mod.lock | 15 ++++ .../issues/kcl-lang/kcl/issue/1760/b/main.k | 1 + 9 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock create mode 100644 pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k diff --git a/pkg/client/client.go b/pkg/client/client.go index 1454ec3d..618e5a4c 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -211,7 +211,14 @@ func (c *KpmClient) AcquireDepSum(dep pkg.Dependency) (string, error) { // ResolveDepsIntoMap will calculate the map of kcl package name and local storage path of the external packages. func (c *KpmClient) ResolveDepsIntoMap(kclPkg *pkg.KclPkg) (map[string]string, error) { - err := c.ResolvePkgDepsMetadata(kclPkg, true) + var err error + if kclPkg.IsVendorMode() { + err = c.VendorDeps(kclPkg) + } else { + kclPkg, err = c.Update( + WithUpdatedKclPkg(kclPkg), + ) + } if err != nil { return nil, err } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 3248f9ab..4c947ca0 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -2254,3 +2254,45 @@ func testPushWithInsecureSkipTLSverify(t *testing.T) { assert.Equal(t, buf.String(), "Called Success\n") } + +func TestIssues(t *testing.T) { + // "kcl-lang/kcl/issue/1760" is the repo where the issue was actually raised and the issue id. + // "testIssue1760" is the test case cover the issue. + RunTestWithGlobalLockAndKpmCli(t, "kcl-lang/kcl/issue/1760", testIssue1760) +} + +func testIssue1760(t *testing.T, kpmcli *KpmClient) { + rootPath := getTestDir("issues") + mainKFilePath := filepath.Join(rootPath, "kcl-lang/kcl/issue/1760", "a", "main.k") + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) + + res, err := kpmcli.Run( + WithRunSource( + &downloader.Source{ + Local: &downloader.Local{ + Path: mainKFilePath, + }, + }, + ), + ) + + if err != nil { + t.Fatal(err) + } + + assert.Contains(t, + utils.RmNewline(buf.String()), + "downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2'", + ) + assert.Contains(t, + utils.RmNewline(buf.String()), + "downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2'", + ) + + assert.Contains(t, + utils.RmNewline(buf.String()), + "downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3'", + ) + assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!") +} diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md new file mode 100644 index 00000000..84229c48 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md @@ -0,0 +1,68 @@ +## Bug Report + +https://github.com/kcl-lang/kcl/issues/1760 + +### 1. Minimal reproduce step (Required) + +1. Two empty modules within the same directory: + +|- modules +| |- a +| | |- kcl.mod +| | |- main.k +| |- b +| | |- kcl.mod +| | |- main.k + +2. Content `/modules/a/kcl.mod` : + +``` +[package] +name = "a" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +b = { path = "../b" } +fluxcd-source-controller = "v1.3.2" +fluxcd-helm-controller = "v1.0.3" +``` + +3. Content `/modules/b/kcl.mod` : + +``` +[package] +name = "b" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +fluxcd-source-controller = "v1.3.2" +``` + +4. Ensure your `$USER/.kcl/kpm/` directory is empty. + + +### 2. What did you expect to see? (Required) +``` +$ kcl run /modules/a/main.k +downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3' +downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2' +downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2' +The_first_kcl_program: Hello World! +``` + +### 3. What did you see instead (Required) +``` +$ kcl run /modules/a/main.k +downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3' +downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2' +downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2' +edge already exists +``` + +--> **kcl exited with error code 1** + +### 4. What is your KCL components version? (Required) + +0.10.8-linux-amd64 diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod new file mode 100644 index 00000000..b2d34c61 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod @@ -0,0 +1,9 @@ +[package] +name = "a" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +b = { path = "../b", version = "0.0.1" } +fluxcd-helm-controller = "v1.0.3" +fluxcd-source-controller = "v1.3.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock new file mode 100644 index 00000000..6a6d847e --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock @@ -0,0 +1,29 @@ +[dependencies] + [dependencies.b] + name = "b" + full_name = "b_0.0.1" + version = "0.0.1" + [dependencies.fluxcd-helm-controller] + name = "fluxcd-helm-controller" + full_name = "fluxcd-helm-controller_v1.0.3" + version = "v1.0.3" + sum = "IfDYAw0NW8XsbUSygAfqkgrJ8LdI7x4NIq7e9TuTbKY=" + reg = "ghcr.io" + repo = "kcl-lang/fluxcd-helm-controller" + oci_tag = "v1.0.3" + [dependencies.fluxcd-source-controller] + name = "fluxcd-source-controller" + full_name = "fluxcd-source-controller_v1.3.2" + version = "v1.3.2" + sum = "iZlc0kXOSajJNUmzvOlcIZgk60WGJbl4xKy4AVWYfkM=" + reg = "ghcr.io" + repo = "kcl-lang/fluxcd-source-controller" + oci_tag = "v1.3.2" + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.31.2" + version = "1.31.2" + sum = "xBZgPsnpVVyWBpahuPQHReeRx28eUHGFoaPeqbct+vs=" + reg = "ghcr.io" + repo = "kcl-lang/k8s" + oci_tag = "1.31.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod new file mode 100644 index 00000000..2ecbc73d --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "b" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +fluxcd-source-controller = "v1.3.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock new file mode 100644 index 00000000..b67bef5c --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock @@ -0,0 +1,15 @@ +[dependencies] + [dependencies.fluxcd-source-controller] + name = "fluxcd-source-controller" + full_name = "fluxcd-source-controller_v1.3.2" + version = "v1.3.2" + reg = "ghcr.io" + repo = "kcl-lang/fluxcd-source-controller" + oci_tag = "v1.3.2" + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.31.2" + version = "1.31.2" + reg = "ghcr.io" + repo = "kcl-lang/k8s" + oci_tag = "1.31.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file From cb101f93396b8cb8e5256ad123565bdd3e11985f Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 20 Nov 2024 11:52:47 +0800 Subject: [PATCH 2/6] fix: fix test case Signed-off-by: zongz --- pkg/client/client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 4c947ca0..f587b815 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -561,8 +561,8 @@ func testResolveDepsVendorMode(t *testing.T) { kpm_home := filepath.Join(testDir, "kpm_home") home_path := filepath.Join(testDir, "my_kcl_resolve_deps_vendor_mode") os.RemoveAll(home_path) - kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1")) - kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2")) + kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1_0.0.1")) + kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2_0.0.1")) depKcl1 := pkg.Dependency{ Name: "kcl1", From 0ab9a8a0063764ae04e74e8dd83b81a54aa8210b Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 20 Nov 2024 11:55:50 +0800 Subject: [PATCH 3/6] fix: fix test case testCompileWithEntryFile Signed-off-by: zongz --- pkg/client/client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index f587b815..2076c25c 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -642,7 +642,7 @@ func testCompileWithEntryFile(t *testing.T) { entry_file := filepath.Join(home_path, "main.k") os.RemoveAll(vendor_path) - kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1")) + kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1_0.0.1")) depKcl1 := pkg.Dependency{ Name: "kcl1", FullName: "kcl1_0.0.1", @@ -656,7 +656,7 @@ func testCompileWithEntryFile(t *testing.T) { }, }, } - kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2")) + kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2_0.0.1")) depKcl2 := pkg.Dependency{ Name: "kcl2", FullName: "kcl2_0.0.1", From 697a41e4506053a8fb4f71a7db4999766071b93d Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 20 Nov 2024 14:14:04 +0800 Subject: [PATCH 4/6] fix: fix test case testCompileWithEntryFile Signed-off-by: zongz --- pkg/client/client_test.go | 2 +- .../test_data/resolve_deps/my_kcl_compile/kcl.mod.lock | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 2076c25c..d41141e1 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -651,7 +651,7 @@ func testCompileWithEntryFile(t *testing.T) { Source: downloader.Source{ Oci: &downloader.Oci{ Reg: "ghcr.io", - Repo: "kcl-lang/kcl2", + Repo: "kcl-lang/kcl1", Tag: "0.0.1", }, }, diff --git a/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock b/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock index b6a76aec..3b7116d3 100644 --- a/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock +++ b/pkg/client/test_data/resolve_deps/my_kcl_compile/kcl.mod.lock @@ -3,7 +3,15 @@ name = "kcl1" full_name = "kcl1_0.0.1" version = "0.0.1" + sum = "c5bjxiHbwJqWCdBwXLOr9MydCTis3nJotrOzozkPsKo=" + reg = "ghcr.io" + repo = "kcl-lang/kcl1" + oci_tag = "0.0.1" [dependencies.kcl2] name = "kcl2" full_name = "kcl2_0.0.1" version = "0.0.1" + sum = "OiA7IJfhi9bLp3d+Phc6ncgWE8XwpXqkGvhF5BOpf34=" + reg = "ghcr.io" + repo = "kcl-lang/kcl2" + oci_tag = "0.0.1" From 5dc9e5704b747faac46c2f9fd09fd28f3c526d0d Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 20 Nov 2024 14:19:08 +0800 Subject: [PATCH 5/6] fix: fix test case testVendorDeps Signed-off-by: zongz --- pkg/client/client_test.go | 1 - pkg/client/vendor_test.go | 22 ++++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index d41141e1..a7717e36 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -55,7 +55,6 @@ func TestWithGlobalLock(t *testing.T) { test.RunTestWithGlobalLock(t, "TestDownloadGitWithPackage", testDownloadGitWithPackage) test.RunTestWithGlobalLock(t, "TestModandLockFilesWithGitPackageDownload", testModandLockFilesWithGitPackageDownload) test.RunTestWithGlobalLock(t, "TestDependencyGraph", testDependencyGraph) - test.RunTestWithGlobalLock(t, "TestVendorWithGlobalLock", testVendorWithGlobalLock) test.RunTestWithGlobalLock(t, "TestPull", testPull) test.RunTestWithGlobalLock(t, "TestPullWithInsecureSkipTLSverify", testPullWithInsecureSkipTLSverify) test.RunTestWithGlobalLock(t, "TestPullWithModSpec", testPullWithModSpec) diff --git a/pkg/client/vendor_test.go b/pkg/client/vendor_test.go index d9bb3952..b9117eee 100644 --- a/pkg/client/vendor_test.go +++ b/pkg/client/vendor_test.go @@ -11,16 +11,15 @@ import ( "kcl-lang.io/kpm/pkg/features" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/settings" - "kcl-lang.io/kpm/pkg/test" "kcl-lang.io/kpm/pkg/utils" ) -func testVendorDeps(t *testing.T) { +func testVendorDeps(t *testing.T, kpmcli *KpmClient) { testDir := getTestDir("resolve_deps") kpm_home := filepath.Join(testDir, "kpm_home") os.RemoveAll(filepath.Join(testDir, "my_kcl")) - kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1")) - kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2")) + kcl1Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl1_0.0.1")) + kcl2Sum, _ := utils.HashDir(filepath.Join(kpm_home, "kcl2_0.0.1")) depKcl1 := pkg.Dependency{ Name: "kcl1", @@ -75,10 +74,8 @@ func testVendorDeps(t *testing.T) { mykclVendorPath := filepath.Join(filepath.Join(testDir, "my_kcl"), "vendor") assert.Equal(t, utils.DirExists(mykclVendorPath), false) - kpmcli, err := NewKpmClient() kpmcli.homePath = kpm_home - assert.Equal(t, err, nil) - err = kpmcli.VendorDeps(&kclPkg) + err := kpmcli.VendorDeps(&kclPkg) assert.Equal(t, err, nil) assert.Equal(t, utils.DirExists(mykclVendorPath), true) assert.Equal(t, utils.DirExists(filepath.Join(mykclVendorPath, "kcl1_0.0.1")), true) @@ -91,7 +88,7 @@ func testVendorDeps(t *testing.T) { os.RemoveAll(filepath.Join(testDir, "my_kcl")) } -func testVendorWithMVS(t *testing.T) { +func testVendorWithMVS(t *testing.T, kpmcli *KpmClient) { features.Enable(features.SupportMVS) defer features.Disable(features.SupportMVS) testDir := getTestDir("test_vendor_mvs") @@ -101,9 +98,6 @@ func testVendorWithMVS(t *testing.T) { pkg.WithSettings(settings.GetSettings()), ) assert.Equal(t, err, nil) - - kpmcli, err := NewKpmClient() - assert.Equal(t, err, nil) err = kpmcli.VendorDeps(kPkg) assert.Equal(t, err, nil) @@ -112,7 +106,7 @@ func testVendorWithMVS(t *testing.T) { assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "vendor", "helloworld_0.1.1")), false) } -func testVendorWithGlobalLock(t *testing.T) { - test.RunTestWithGlobalLock(t, "TestVendorDeps", testVendorDeps) - test.RunTestWithGlobalLock(t, "TestVendorWithMVS", testVendorWithMVS) +func TestVendorWithGlobalLock(t *testing.T) { + RunTestWithGlobalLockAndKpmCli(t, "TestVendorDeps", testVendorDeps) + RunTestWithGlobalLockAndKpmCli(t, "TestVendorWithMVS", testVendorWithMVS) } From 87b7f0b85322bcfccbb274a6d909ea1e5ead4c25 Mon Sep 17 00:00:00 2001 From: zongz Date: Wed, 20 Nov 2024 14:54:19 +0800 Subject: [PATCH 6/6] fix: fix test case TestRunWithOciDownloader Signed-off-by: zongz --- .../run_with_default_dep/kcl.mod.lock.expect | 1 + pkg/client/test_data/test_run_git_package/kcl.mod | 2 +- .../test_run_with_modspec_version/kcl.mod.expect | 2 +- .../kcl.mod.lock.expect | 1 + pkg/visitor/visitor.go | 12 ++++++++++++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/client/test_data/run_with_default_dep/kcl.mod.lock.expect b/pkg/client/test_data/run_with_default_dep/kcl.mod.lock.expect index c1bebf8c..7eaf9cba 100644 --- a/pkg/client/test_data/run_with_default_dep/kcl.mod.lock.expect +++ b/pkg/client/test_data/run_with_default_dep/kcl.mod.lock.expect @@ -3,6 +3,7 @@ name = "helloworld" full_name = "helloworld_0.1.2" version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" oci_tag = "0.1.2" diff --git a/pkg/client/test_data/test_run_git_package/kcl.mod b/pkg/client/test_data/test_run_git_package/kcl.mod index 5e0b1cba..cc457753 100644 --- a/pkg/client/test_data/test_run_git_package/kcl.mod +++ b/pkg/client/test_data/test_run_git_package/kcl.mod @@ -4,4 +4,4 @@ edition = "v0.8.0" version = "0.0.1" [dependencies] -k8s = { git = "https://github.com/kcl-lang/modules.git", commit = "ee03122b5f45b09eb48694422fc99a0772f6bba8", package = "k8s" } +k8s = { git = "https://github.com/kcl-lang/modules.git", commit = "ee03122b5f45b09eb48694422fc99a0772f6bba8", package = "k8s", version = "1.31" } diff --git a/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.expect b/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.expect index 46d3ecdf..002d6627 100644 --- a/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.expect +++ b/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.expect @@ -4,4 +4,4 @@ edition = "v0.10.0" version = "0.0.1" [dependencies] -helloworld = { version = "0.1.2" } \ No newline at end of file +helloworld = "0.1.2" \ No newline at end of file diff --git a/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.lock.expect b/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.lock.expect index c1bebf8c..7eaf9cba 100644 --- a/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.lock.expect +++ b/pkg/client/test_data/test_run_with_modspec_version/kcl.mod.lock.expect @@ -3,6 +3,7 @@ name = "helloworld" full_name = "helloworld_0.1.2" version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" oci_tag = "0.1.2" diff --git a/pkg/visitor/visitor.go b/pkg/visitor/visitor.go index 7b005f97..447fedf3 100644 --- a/pkg/visitor/visitor.go +++ b/pkg/visitor/visitor.go @@ -205,10 +205,22 @@ func (rv *RemoteVisitor) Visit(s *downloader.Source, v visitFunc) error { // update the local module path with the latest version. if len(rv.VisitedSpace) != 0 { modFullPath = s.LocalPath(filepath.Join(rv.VisitedSpace, s.Type(), "src")) + if !utils.DirExists(modFullPath) { + err = os.MkdirAll(modFullPath, 0755) + if err != nil { + return err + } + } } // update the cache path with the latest version. if rv.EnableCache { cacheFullPath = s.CachePath(filepath.Join(rv.CachePath, s.Type(), "cache")) + if !utils.DirExists(cacheFullPath) { + err = os.MkdirAll(cacheFullPath, 0755) + if err != nil { + return err + } + } } }