You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by jp...@apache.org on 2022/05/16 15:12:13 UTC
[camel-k] branch release-1.9.x updated (ab9e6d75f -> 9ad6feedc)
This is an automated email from the ASF dual-hosted git repository.
jpoth pushed a change to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
from ab9e6d75f fix(e2e): rest yaml definition as Camel 3.15
new add82a8af Fix #3257: work with relative paths on windows to avoid extra semicolon
new 9ad6feedc Fix: support absolute paths on Windows
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pkg/cmd/run.go | 51 ++++++++++++++++++++++++++++++++++++-----
pkg/cmd/run_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+), 6 deletions(-)
[camel-k] 02/02: Fix: support absolute paths on Windows
Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9ad6feedc121e8797b1ab9a4311e2bdc41cf7ba3
Author: John Poth <po...@gmail.com>
AuthorDate: Fri May 13 12:10:07 2022 +0200
Fix: support absolute paths on Windows
(cherry picked from commit aa14a2355004288d7e3f13fde06b17d6674a5dc0)
---
pkg/cmd/run.go | 24 ++++++++++++++-----
pkg/cmd/run_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 6 deletions(-)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index b32fc6f33..7d015ba1f 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -789,12 +789,7 @@ func resolvePodTemplate(ctx context.Context, cmd *cobra.Command, templateSrc str
func uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integrationName string, cmd *cobra.Command, integration *v1.Integration) error {
path := strings.TrimPrefix(item, "file://")
- localPath := path
- targetPath := ""
- if i := strings.Index(path, ":"); i > 0 {
- targetPath = path[i+1:]
- localPath = path[:i]
- }
+ localPath, targetPath := getPaths(path, runtimeos.GOOS, filepath.IsAbs(path))
options := getSpectrumOptions(platform, cmd)
dirName, err := getDirName(localPath)
if err != nil {
@@ -840,6 +835,23 @@ func uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integr
})
}
+func getPaths(path string, os string, isAbs bool) (localPath string, targetPath string) {
+ localPath = path
+ targetPath = ""
+ parts := strings.Split(path, ":")
+ if len(parts) > 1 {
+ if os != "windows" || !isAbs {
+ localPath = parts[0]
+ targetPath = parts[1]
+ } else if isAbs && len(parts) == 3 {
+ // special case on Windows for absolute paths e.g C:\foo\bar\test.csv:remote/path
+ localPath = fmt.Sprintf("%s:%s", parts[0], parts[1])
+ targetPath = parts[2]
+ }
+ }
+ return localPath, targetPath
+}
+
func getMountPath(targetPath string, dirName string, path string) (string, error) {
// if the target path is a file then use that as the exact mount path
if filepath.Ext(targetPath) != "" {
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index b865fb7ce..f2fe2e6b4 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -680,3 +680,69 @@ func TestMissingTrait(t *testing.T) {
assert.Equal(t, "Error: bogus.fail=i-must-fail is not a valid trait property\n", output)
assert.NotNil(t, err)
}
+
+func TestGetsPaths(t *testing.T) {
+ tests := []struct {
+ path string
+ localPath string
+ remotePath string
+ os string
+ isAbs bool
+ }{
+ {
+ path: "C:\\USER\\HOME\\:remote/path",
+ localPath: "C:\\USER\\HOME\\",
+ remotePath: "remote/path",
+ os: "windows",
+ isAbs: true,
+ },
+ {
+ path: "src\\main\\resources:remote/path",
+ localPath: "src\\main\\resources",
+ remotePath: "remote/path",
+ os: "windows",
+ },
+ {
+ path: "C:\\USER\\HOME\\",
+ localPath: "C:\\USER\\HOME\\",
+ remotePath: "",
+ os: "windows",
+ isAbs: true,
+ },
+ {
+ path: "src\\main\\resources",
+ localPath: "src\\main\\resources",
+ remotePath: "",
+ os: "windows",
+ },
+ {
+ path: "/home/user/name/dir:/remote/path",
+ localPath: "/home/user/name/dir",
+ remotePath: "/remote/path",
+ os: "linux",
+ isAbs: true,
+ }, {
+ path: "/home/user/name/dir",
+ localPath: "/home/user/name/dir",
+ remotePath: "",
+ os: "linux",
+ isAbs: true,
+ }, {
+ path: "src/main/resources:remote/path",
+ localPath: "src/main/resources",
+ remotePath: "remote/path",
+ os: "linux",
+ }, {
+ path: "src/main/resources",
+ localPath: "src/main/resources",
+ remotePath: "",
+ os: "linux",
+ },
+ }
+ for _, test := range tests {
+ localPath, targetPath := getPaths(test.path, test.os, test.isAbs)
+ assert.Equal(t, test.localPath, localPath)
+ assert.Equal(t, test.remotePath, targetPath)
+
+ }
+}
[camel-k] 01/02: Fix #3257: work with relative paths on windows to avoid extra semicolon
Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit add82a8af0266b2a6bba2c9deb0556ef6465d656
Author: John Poth <po...@gmail.com>
AuthorDate: Thu May 12 12:13:52 2022 +0200
Fix #3257: work with relative paths on windows to avoid extra semicolon
(cherry picked from commit 89794bfad8184e6f2553ed039892bf512e2de9ea)
---
pkg/cmd/run.go | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 247d9e1a5..b32fc6f33 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -39,6 +39,7 @@ import (
"path/filepath"
"reflect"
"regexp"
+ runtimeos "runtime"
"strings"
"syscall"
@@ -952,6 +953,15 @@ func extractGav(src *zip.File, localPath string) (maven.Dependency, bool) {
func uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options) error {
artifactHTTPPath := getArtifactHTTPPath(dependency, platform, ns)
options.Target = fmt.Sprintf("%s/%s:%s", platform.Spec.Build.Registry.Address, artifactHTTPPath, dependency.Version)
+ if runtimeos.GOOS == "windows" {
+ // workaround for https://github.com/container-tools/spectrum/issues/8
+ // work with relative paths instead
+ rel, err := getRelativeToWorkingDirectory(path)
+ if err != nil {
+ return err
+ }
+ path = rel
+ }
_, err := spectrum.Build(options, fmt.Sprintf("%s:.", path))
if err != nil {
return err
@@ -960,6 +970,23 @@ func uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v
return uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
}
+// Deprecated: workaround for https://github.com/container-tools/spectrum/issues/8
+func getRelativeToWorkingDirectory(path string) (string, error) {
+ wd, err := os.Getwd()
+ if err != nil {
+ return "", err
+ }
+ abs, err := filepath.Abs(path)
+ if err != nil {
+ return "", err
+ }
+ path, err = filepath.Rel(wd, abs)
+ if err != nil {
+ return "", err
+ }
+ return path, nil
+}
+
// Currently swallows errors because our Project model is incomplete.
// Most of the time it is irrelevant for our use case (GAV).
// nolint:errcheck