diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index b34c95b4ec73..26a946badfda 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -152,6 +152,7 @@ var allTests = integration.TestFuncs( testNamedMultiplatformInputContext, testNamedFilteredContext, testEmptyDestDir, + testPreserveDestDirSlash, testCopyLinkDotDestDir, testCopyLinkEmptyDestDir, testCopyChownCreateDest, @@ -547,6 +548,42 @@ RUN cmd /V:on /C "set /p tfcontent= 1 && hasTrailingSlash(origPath) && inputOS == "windows" { + // cleanedPath already comes with platform specific separators + return cleanedPath + string(filepath.Separator) + } + return cleanedPath } diff --git a/util/system/path_unix.go b/util/system/path_unix.go new file mode 100644 index 000000000000..1cc02782435b --- /dev/null +++ b/util/system/path_unix.go @@ -0,0 +1,10 @@ +//go:build !windows +// +build !windows + +package system + +import "strings" + +func hasTrailingSlash(origPath string) bool { + return strings.HasSuffix(origPath, "/") +} diff --git a/util/system/path_windows.go b/util/system/path_windows.go new file mode 100644 index 000000000000..8bb70e732090 --- /dev/null +++ b/util/system/path_windows.go @@ -0,0 +1,9 @@ +package system + +import "strings" + +func hasTrailingSlash(origPath string) bool { + // Windows allows for both \\ and / as path separators. + return strings.HasSuffix(origPath, "\\") || + strings.HasSuffix(origPath, "/") +}