diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c92b3a58..5a73adff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.17.x, 1.21.x, 1.22.x] + go-version: [1.18.x, 1.21.x, 1.22.x] platform: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-latest, macos-12, macos-14] runs-on: ${{ matrix.platform }} steps: diff --git a/mount/flags_unix.go b/mount/flags_unix.go index 19fa61fc..ad3ba0a7 100644 --- a/mount/flags_unix.go +++ b/mount/flags_unix.go @@ -100,14 +100,14 @@ func MergeTmpfsOptions(options []string) ([]string, error) { } continue } - opt := strings.SplitN(option, "=", 2) - if len(opt) != 2 || !validFlags[opt[0]] { + opt, _, ok := strings.Cut(option, "=") + if !ok || !validFlags[opt] { return nil, fmt.Errorf("invalid tmpfs option %q", opt) } - if !dataCollisions[opt[0]] { + if !dataCollisions[opt] { // We prepend the option and add to collision map newOptions = append([]string{option}, newOptions...) - dataCollisions[opt[0]] = true + dataCollisions[opt] = true } } diff --git a/mount/go.mod b/mount/go.mod index 000363d7..046fd514 100644 --- a/mount/go.mod +++ b/mount/go.mod @@ -1,6 +1,6 @@ module github.com/moby/sys/mount -go 1.17 +go 1.18 require ( github.com/moby/sys/mountinfo v0.7.2 diff --git a/mount/mounter_linux_test.go b/mount/mounter_linux_test.go index 8d5c87ab..461deb49 100644 --- a/mount/mounter_linux_test.go +++ b/mount/mounter_linux_test.go @@ -212,7 +212,8 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) { // clean strips off any value param after the colon func clean(v string) string { - return strings.SplitN(v, ":", 2)[0] + out, _, _ := strings.Cut(v, ":") + return out } // has returns true if key is a member of m diff --git a/mountinfo/go.mod b/mountinfo/go.mod index 42a37060..029f7374 100644 --- a/mountinfo/go.mod +++ b/mountinfo/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/mountinfo -go 1.17 +go 1.18 require golang.org/x/sys v0.1.0 diff --git a/mountinfo/mountinfo_linux.go b/mountinfo/mountinfo_linux.go index b32b5c9b..43ced2c1 100644 --- a/mountinfo/mountinfo_linux.go +++ b/mountinfo/mountinfo_linux.go @@ -75,7 +75,20 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) { } } - p := &Info{} + major, minor, ok := strings.Cut(fields[2], ":") + if !ok { + return nil, fmt.Errorf("parsing '%s' failed: unexpected major:minor pair %s", text, fields[2]) + } + + p := &Info{ + ID: toInt(fields[0]), + Parent: toInt(fields[1]), + Major: toInt(major), + Minor: toInt(minor), + Options: fields[5], + Optional: strings.Join(fields[6:sepIdx], " "), // zero or more optional fields + VFSOptions: fields[sepIdx+3], + } p.Mountpoint, err = unescape(fields[4]) if err != nil { @@ -89,28 +102,12 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) { if err != nil { return nil, fmt.Errorf("parsing '%s' failed: source: %w", fields[sepIdx+2], err) } - p.VFSOptions = fields[sepIdx+3] - - // ignore any numbers parsing errors, as there should not be any - p.ID, _ = strconv.Atoi(fields[0]) - p.Parent, _ = strconv.Atoi(fields[1]) - mm := strings.SplitN(fields[2], ":", 3) - if len(mm) != 2 { - return nil, fmt.Errorf("parsing '%s' failed: unexpected major:minor pair %s", text, mm) - } - p.Major, _ = strconv.Atoi(mm[0]) - p.Minor, _ = strconv.Atoi(mm[1]) p.Root, err = unescape(fields[3]) if err != nil { return nil, fmt.Errorf("parsing '%s' failed: root: %w", fields[3], err) } - p.Options = fields[5] - - // zero or more optional fields - p.Optional = strings.Join(fields[6:sepIdx], " ") - // Run the filter after parsing all fields. var skip, stop bool if filter != nil { @@ -248,3 +245,10 @@ func unescape(path string) (string, error) { return string(buf[:bufLen]), nil } + +// toInt converts a string to an int, and ignores any numbers parsing errors, +// as there should not be any. +func toInt(s string) int { + i, _ := strconv.Atoi(s) + return i +} diff --git a/sequential/go.mod b/sequential/go.mod index 4e620fe1..2403a3d0 100644 --- a/sequential/go.mod +++ b/sequential/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/sequential -go 1.17 +go 1.18 require golang.org/x/sys v0.1.0 diff --git a/signal/go.mod b/signal/go.mod index f76c5ad3..29a7be48 100644 --- a/signal/go.mod +++ b/signal/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/signal -go 1.17 +go 1.18 require golang.org/x/sys v0.1.0 diff --git a/symlink/go.mod b/symlink/go.mod index 9b73f0c5..01b5b515 100644 --- a/symlink/go.mod +++ b/symlink/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/symlink -go 1.17 +go 1.18 require golang.org/x/sys v0.1.0 diff --git a/user/go.mod b/user/go.mod index 1c62fac9..94e2d1f3 100644 --- a/user/go.mod +++ b/user/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/user -go 1.17 +go 1.18 require golang.org/x/sys v0.1.0