Skip to content

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 28, 2023

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:

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 28, 2023

Otherwise we could default hostRoot to / and use filepath.Join everywhere it gets used.
I don't see the value of using it though (and what if the user then configures driver with hostRoot empty?)

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 28, 2023

/milestone v0.7.0

@poiana poiana added this to the v0.7.0 milestone Nov 28, 2023
Copy link
Member

@leogr leogr left a 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?

@poiana poiana added size/L and removed size/XS labels Nov 29, 2023
@FedeDP FedeDP force-pushed the fix/no_filepath_join branch from df126c9 to cc56c0a Compare November 29, 2023 10:06
@FedeDP FedeDP changed the title fix(cmd/driver,pkg/driver): avoid using filepath.Join when joining host-root fix(cmd/driver,pkg/driver): avoid string concatenation for host-root Nov 29, 2023
@@ -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) {
Copy link
Contributor Author

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),
Copy link
Contributor Author

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)
Copy link
Contributor Author

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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

Copy link
Member

@alacuku alacuku left a 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]>
@FedeDP FedeDP force-pushed the fix/no_filepath_join branch from cc56c0a to 2c2f53b Compare November 29, 2023 11:12
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 29, 2023

squashed to a single commit :)

@poiana
Copy link
Contributor

poiana commented Nov 29, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 077b671 into main Nov 29, 2023
@poiana poiana deleted the fix/no_filepath_join branch November 29, 2023 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants