Skip to content

Commit

Permalink
chore: quick tidy-up of string ops
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Nov 24, 2024
1 parent eca8ae9 commit 47c69b4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (c *Container) ID() string {
}

func (c *Container) Rootfs() string {
if strings.Index(c.Spec.Root.Path, "/") == 0 {
if strings.HasPrefix(c.Spec.Root.Path, "/") {
return c.Spec.Root.Path
}

Expand Down
8 changes: 1 addition & 7 deletions container/filesystem/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,7 @@ func mountDefaultDevices(rootfs string) error {
func mountSpecDevices(devices []specs.LinuxDevice, rootfs string) error {
for _, dev := range devices {

var absPath string
if strings.Index(dev.Path, "/") == 0 {
relPath := strings.TrimPrefix(dev.Path, "/")
absPath = filepath.Join(rootfs, relPath)
} else {
absPath = filepath.Join(rootfs, dev.Path)
}
absPath := filepath.Join(rootfs, strings.TrimPrefix(dev.Path, "/"))

dt := map[string]uint32{
"b": unix.S_IFBLK,
Expand Down
8 changes: 1 addition & 7 deletions container/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,7 @@ func devIsInSpec(mounts []specs.Mount, dev string) bool {

func mountDevices(devices []specs.LinuxDevice, rootfs string) error {
for _, dev := range devices {
var absPath string
if strings.Index(dev.Path, "/") == 0 {
relPath := strings.TrimPrefix(dev.Path, "/")
absPath = filepath.Join(rootfs, relPath)
} else {
absPath = filepath.Join(rootfs, dev.Path)
}
absPath := filepath.Join(rootfs, strings.TrimPrefix(dev.Path, "/"))

if _, err := os.Stat(absPath); os.IsNotExist(err) {
f, err := os.Create(absPath)
Expand Down

0 comments on commit 47c69b4

Please sign in to comment.