-
Notifications
You must be signed in to change notification settings - Fork 62
fix(cmd/driver,pkg/driver): avoid string concatenation for host-root #358
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
Conversation
Otherwise we could default hostRoot to |
/milestone v0.7.0 |
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.
What about using https://pkg.go.dev/path/filepath#Clean instead?
df126c9
to
cc56c0a
Compare
filepath.Join
when joining host-root@@ -125,6 +125,9 @@ func (o *driverConfigOptions) RunDriverConfig(ctx context.Context, cmd *cobra.Co | |||
}) | |||
} | |||
if f := cmd.Flags().Lookup("host-root"); f != nil && f.Changed { | |||
if !filepath.IsAbs(o.HostRoot) { |
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.
Must be absolute path now.
@@ -208,7 +208,7 @@ func init() { | |||
Name: "falco", | |||
Repos: []string{"https://download.falco.org/driver"}, | |||
Version: "", | |||
HostRoot: "", | |||
HostRoot: string(os.PathSeparator), |
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.
New default.
var ErrUnsupported = errors.New("failed to determine distro") | ||
var ( | ||
distros = map[string]Distro{} | ||
hostRoot = string(os.PathSeparator) |
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.
Package local variable to store running hostRoot.
// by cycling on all supported distros and checking them one by one. | ||
// | ||
//nolint:gocritic // the method shall not be able to modify kr | ||
func DiscoverDistro(kr kernelrelease.KernelRelease, hostRoot string) (Distro, error) { | ||
distro, err := getOSReleaseDistro(&kr, hostRoot) | ||
func Discover(kr kernelrelease.KernelRelease, hostroot string) (Distro, error) { |
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.
Renamed.
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.
/LGTM
…ion for hostroot. Moreover, hostRoot will now default to `/`, and it will be stored as package local variable in driverdistro package, to forwarding it where needed. Signed-off-by: Federico Di Pierro <[email protected]>
cc56c0a
to
2c2f53b
Compare
squashed to a single commit :) |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alacuku, FedeDP, leogr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area library
What this PR does / why we need it:
Avoid string concatenation for hostroot.
Moreover, hostRoot will now default to
/
, and it will be stored as package local variable in driverdistro package, to be forwarded where needed.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer: