-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: util/path: CheckSystemDriveAndRemoveDriveLetter to preserve
/
on
WCOW The call to CheckSystemDriveAndRemoveDriveLetter() does not preserve the trailing `/` or `\\`. This happens because `filepath.Clean()` strips away any trailing slashes. For example `/sample/` will be `\\sample` on Windows. This function was mainly written for Windows scenarios, which have System Drive Letters like C:/, etc. This was causing cases like `COPY testfile /testdir/` to be intepreted as `COPY testfile /testdir`, and if `testdir` is not explictly created before the call, it ends up being treated as a destination file other than a directory. Fix this by checking that if we have a trailing `/` or `\\`, we preserve it after the call to `filepath.Clean()`. Fixes #5249 Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
- Loading branch information
1 parent
734a6cc
commit 288b5db
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package system | ||
|
||
// this was addressing a Windows-specific issue #5249, | ||
// does nothing on unix. | ||
func keepTrailingSlash(cleanedPath, _, _ string) string { | ||
return cleanedPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package system | ||
|
||
import "strings" | ||
|
||
// Checks if a path other than root has a trailing slash | ||
// and retains it. See https://github.com/moby/buildkit/issues/5249 | ||
// Expects cleanedPath to have gone through filepath.Clean | ||
func keepTrailingSlash(cleanedPath, origPath, inputOS string) string { | ||
hasTrailingSlash := strings.HasSuffix(origPath, "\\") || | ||
strings.HasSuffix(origPath, "/") | ||
|
||
if len(cleanedPath) > 1 && hasTrailingSlash && inputOS == "windows" { | ||
// for cleaned paths, / will turn to \\ | ||
return cleanedPath + "\\" | ||
} | ||
return cleanedPath | ||
} |