From 47c69b4e5b2d891bf2627d329109673807736b10 Mon Sep 17 00:00:00 2001 From: nixpig <143995476+nixpig@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:43:50 +0000 Subject: [PATCH] chore: quick tidy-up of string ops --- container/container.go | 2 +- container/filesystem/devices.go | 8 +------- container/filesystem/filesystem.go | 8 +------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/container/container.go b/container/container.go index f6edcc0..b7e316a 100644 --- a/container/container.go +++ b/container/container.go @@ -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 } diff --git a/container/filesystem/devices.go b/container/filesystem/devices.go index 6699705..f0226f1 100644 --- a/container/filesystem/devices.go +++ b/container/filesystem/devices.go @@ -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, diff --git a/container/filesystem/filesystem.go b/container/filesystem/filesystem.go index bd30bc1..b6d4cfa 100644 --- a/container/filesystem/filesystem.go +++ b/container/filesystem/filesystem.go @@ -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)