mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
rebase: update replaced k8s.io modules to v0.33.0
Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
dd77e72800
commit
107407b44b
52
e2e/vendor/github.com/opencontainers/cgroups/internal/path/path.go
generated
vendored
Normal file
52
e2e/vendor/github.com/opencontainers/cgroups/internal/path/path.go
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
package path
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/opencontainers/cgroups"
|
||||
)
|
||||
|
||||
// Inner returns a path to cgroup relative to a cgroup mount point, based
|
||||
// on cgroup configuration, or an error, if cgroup configuration is invalid.
|
||||
// To be used only by fs cgroup managers (systemd has different path rules).
|
||||
func Inner(c *cgroups.Cgroup) (string, error) {
|
||||
if (c.Name != "" || c.Parent != "") && c.Path != "" {
|
||||
return "", errors.New("cgroup: either Path or Name and Parent should be used")
|
||||
}
|
||||
|
||||
// XXX: Do not remove cleanPath. Path safety is important! -- cyphar
|
||||
innerPath := cleanPath(c.Path)
|
||||
if innerPath == "" {
|
||||
cgParent := cleanPath(c.Parent)
|
||||
cgName := cleanPath(c.Name)
|
||||
innerPath = filepath.Join(cgParent, cgName)
|
||||
}
|
||||
|
||||
return innerPath, nil
|
||||
}
|
||||
|
||||
// cleanPath is a copy of github.com/opencontainers/runc/libcontainer/utils.CleanPath.
|
||||
func cleanPath(path string) string {
|
||||
// Deal with empty strings nicely.
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Ensure that all paths are cleaned (especially problematic ones like
|
||||
// "/../../../../../" which can cause lots of issues).
|
||||
|
||||
if filepath.IsAbs(path) {
|
||||
return filepath.Clean(path)
|
||||
}
|
||||
|
||||
// If the path isn't absolute, we need to do more processing to fix paths
|
||||
// such as "../../../../<etc>/some/path". We also shouldn't convert absolute
|
||||
// paths to relative ones.
|
||||
path = filepath.Clean(string(os.PathSeparator) + path)
|
||||
// This can't fail, as (by definition) all paths are relative to root.
|
||||
path, _ = filepath.Rel(string(os.PathSeparator), path)
|
||||
|
||||
return path
|
||||
}
|
Reference in New Issue
Block a user