-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: util/path: CheckSystemDriveAndRemoveDriveLetter
to preserve /
#5317
base: master
Are you sure you want to change the base?
Conversation
/
CheckSystemDriveAndRemoveDriveLetter
to preserve /
Looking into the CI failures... |
Found the regression caused by this, thankfully coz of the checked in integration tests! Dockerfile: FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
COPY test1.txt /sample/
RUN type \sample\test1.txt
COPY test1.txt /
COPY test1.txt /test2.txt
RUN type test1.txt
RUN type test2.txt Build log:
Fixing. |
ac8552f
to
af77ee9
Compare
af77ee9
to
be65686
Compare
36e398e
to
1a5289c
Compare
1a5289c
to
c55dbc3
Compare
c55dbc3
to
288b5db
Compare
288b5db
to
c91001c
Compare
aca0ccb
to
e8ae74c
Compare
5dd50bb
to
2d75bcd
Compare
2d75bcd
to
1dc5d2b
Compare
LGTM. Waiting for a second review before merging. |
Thanks!
…On Wed, Oct 9, 2024, 12:28 Gabriel ***@***.***> wrote:
LGTM. Waiting for a second review before merging.
—
Reply to this email directly, view it on GitHub
<#5317 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB7ZEMYKEKKZE5GDTAXVQLZ2TZKPAVCNFSM6AAAAABN6FHHEWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBRHAYDSOBYGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@crazy-max @tonistiigi -- can take a look at this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't understand this in relation to #5317 (comment) comment.
We have a NormalizePath
function that takes keepSlash
parameter. Afaics that implementation is still linux-specific and does not understand windows inputOS with backslashes.
This adds a new function cleanPath()
that doesn't take keepSlash
but automatically adds /
is input path contained it. That is not the behavior of path.Clean
so minimally function should be called cleanPathKeepSlash()
, but ideally we should keep the functionality to keep slash into a single function and not multiple, and NormalizePath
should not be linux-specific.
Hi @tonistiigi --
The problem is that we don't get a chance to get to buildkit/frontend/dockerfile/dockerfile2llb/convert.go Lines 1801 to 1822 in 4b4a9aa
I'm okay with renaming this for clarity. On the second part, the only problem is that we don't get to the The more simplistic option I had is just adding back the trailing slash before we call into Your thoughts? |
Don't worry about Go backwards compatibility. We only care about API backwards compatibility.
NormalizePath also calls into CheckSystemDriveAndRemoveDriveLetter (2x actually) so it looks like there might be some duplication in the codepath. Better to make it clear which functions responsibility it is to keep the slash and make sure this implementation is cross-platform capable. |
Thanks for this, we can then have
I also noticed that multiple runs through |
1dc5d2b
to
d750530
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL at the new changes I've made from the review recommendations. @gabriel-samfira @tonistiigi
d750530
to
3410347
Compare
Will investigate and fix the CI failures. |
be12cf3
to
b8d27d1
Compare
CI failures now fixed, PTAL @gabriel-samfira @tonistiigi |
util/system/path.go
Outdated
// Returns path with platform specific separators. | ||
// See https://github.com/moby/buildkit/issues/5249 | ||
func cleanPath(origPath string) string { | ||
cleanedPath := filepath.Clean(origPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this has not been resolved?
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 and `/sample` on Linux. 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()`. Also refactor `CheckSystemDriveAndRemoveDriveLetter` function to take an extra keepSlash bool param, to be consistent with what is passed to `NormalizePath`. The rest of the calls to this function has left keepSlash = false as the default behavior. Fixes moby#5249 PS. Also fixed for cross-building from Linux scenario, taking care for paths like `\\sample\\` that are not changed when run through `filepath.Clean()`. Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
b8d27d1
to
5d4b38c
Compare
The call to CheckSystemDriveAndRemoveDriveLetter() does not preserve the trailing
/
or\\
. This happens becausefilepath.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 asCOPY testfile /testdir
, and iftestdir
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 tofilepath.Clean()
.Fixes #5249
PS.
Also fixed for cross-building Windows from Linux, that would fail silently:
Repro dockerfile without
RUN
:Build log:
Checking results,
sample
is a file instead of a directory:NOTE: also covered cases like, where platform-specific
filepath.Clean()
won't strip out the\\
on Linux: