-
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
Add path handling functions #3907
Add path handling functions #3907
Conversation
util/system/path.go
Outdated
if platform == "" { | ||
platform = runtime.GOOS | ||
} | ||
|
||
if platform != "windows" { | ||
return path, nil | ||
} |
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 think the previous impl was better with CheckSystemDriveAndRemoveDriveLetter(path string)
in path_unix.go
and path_windows.go
files. Can we keep that?
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.
Windows hosts can theoretically build Linux images, as it also has support for LCOW (Linux Containers on Windows). We should also be able to build Windows images on Linux. It's a good idea to use the target platform as an indicator of how to handle paths (as well as other things).
In short, the platform we're running on is not necessarily the platform we're building for.
@tonistiigi expressed a similar concern here: #3322 (comment)
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.
There was a similar discussion in containerd. Which is why, in that instance, we ended up using the image.ImageSpec.OS
as an indicator of how to handle the volumes when copying existing contents.
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.
Why are the tests OS specific? I thought the functions work the same independently from the current platform based on the input platform.
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.
Why are the tests OS specific? I thought the functions work the same independently from the current platform based on the input platform.
Good point. I will move them to a non OS specific file. Thanks for the review!
There are several places throughout the code where we repeat the same normalization patterns for paths. This change adds a couple of helper functions and makes CheckSystemDriveAndRemoveDriveLetter() on all platforms. Additionally, all functions accept a platform flag that indicates the target OS we're building the image for. Decissions are made based on this flag instead of checking the platform on which buildkit is running. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
7b2272b
to
d6124fc
Compare
@tonistiigi changes made. PTAL. |
// - optionally keep the trailing slashes on paths | ||
// - paths are returned using forward slashes | ||
func NormalizePath(parent, newPath, inputOS string, keepSlash bool) (string, error) { | ||
if inputOS == "" { |
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.
Do we need to make os optional? Can't the caller just always pass it?
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 can have the functions err out if it's empty if you prefer. The caller can of course, always pass it, even if they just pass the value of runtime.GOOS
.
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.
Was not sure what the preference was 😄 .
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'm also fine with just having unix as default like the toSlash
etc do. Just having the behavior be different based on runtime.GOOS
looks like something that can easily break in the future without we realizing it.
Make sure the behavior is consistent (eg. IsAbs is different atm).
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.
Fair enough. I set linux
as the default.
d71c0ed
to
f22032f
Compare
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
f22032f
to
feeb3ff
Compare
There are several places throughout the code where we repeat the same normalization patterns for paths. This change adds a couple of helper functions and makes CheckSystemDriveAndRemoveDriveLetter() on all platforms.
Additionally, all functions accept a platform flag that indicates the target OS we're building the image for. Decisions are made based on this flag instead of checking the platform on which buildkit is running.
This change was split from #3322. The functions added here are not yet called anywhere in the code. A subsequent PR which will depend on this one will be proposed soon with the bits that make use of these functions.