Skip to content

Commit

Permalink
use filepath instead of path
Browse files Browse the repository at this point in the history
Originally, this package was documented to be for paths separated by forward
slashes, but I was recently pointed to the updated package description, which
amended the documentation (see https://go-review.googlesource.com/32423) and
added:

> To manipulate operating system paths, use the path/filepath package.

A later patch (https://go-review.googlesource.com/45653) tweaked the description
again, adding to the `path/filepath` package:

> To process paths such as URLs that always use forward slashes regardless of
> the operating system, see the path package.

And to the `path` package

> This package does not deal with Windows paths with drive letters or backslashes;
> to manipulate operating system paths, use the path/filepath package.

I expect it to be "fine" in general to use the `path` package for Unix/Linux, but
from both patches, the intent of the Go maintainers is to use `path/filepath`
for anything file(system) related, so let's adapt to that.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 10, 2022
1 parent a22d64b commit 2e30223
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions go-selinux/selinux_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"math/big"
"os"
"os/user"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -461,10 +460,10 @@ func attrPath(attr string) string {
})

if haveThreadSelf {
return path.Join(threadSelfPrefix, attr)
return filepath.Join(threadSelfPrefix, attr)
}

return path.Join("/proc/self/task/", strconv.Itoa(unix.Gettid()), "/attr/", attr)
return filepath.Join("/proc/self/task", strconv.Itoa(unix.Gettid()), "attr", attr)
}

func readAttr(attr string) (string, error) {
Expand Down Expand Up @@ -815,7 +814,7 @@ func reserveLabel(label string) {
}

func selinuxEnforcePath() string {
return path.Join(getSelinuxMountPoint(), "enforce")
return filepath.Join(getSelinuxMountPoint(), "enforce")
}

// enforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
Expand Down Expand Up @@ -940,7 +939,7 @@ func openContextFile() (*os.File, error) {
if f, err := os.Open(contextFile); err == nil {
return f, nil
}
return os.Open(filepath.Join(policyRoot(), "/contexts/lxc_contexts"))
return os.Open(filepath.Join(policyRoot(), "contexts", "lxc_contexts"))
}

func loadLabels() {
Expand Down Expand Up @@ -1043,7 +1042,7 @@ func addMcs(processLabel, fileLabel string) (string, string) {

// securityCheckContext validates that the SELinux label is understood by the kernel
func securityCheckContext(val string) error {
return os.WriteFile(path.Join(getSelinuxMountPoint(), "context"), []byte(val), 0o644)
return os.WriteFile(filepath.Join(getSelinuxMountPoint(), "context"), []byte(val), 0o644)
}

// copyLevel returns a label with the MLS/MCS level from src label replaced on
Expand Down

0 comments on commit 2e30223

Please sign in to comment.