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 <[email protected]> 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) + + } +}
