Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions mount/flags_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion mount/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion mount/mounter_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mountinfo/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/moby/sys/mountinfo

go 1.17
go 1.18

require golang.org/x/sys v0.1.0
38 changes: 21 additions & 17 deletions mountinfo/mountinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion sequential/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/moby/sys/sequential

go 1.17
go 1.18

require golang.org/x/sys v0.1.0
2 changes: 1 addition & 1 deletion signal/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/moby/sys/signal

go 1.17
go 1.18

require golang.org/x/sys v0.1.0
2 changes: 1 addition & 1 deletion symlink/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/moby/sys/symlink

go 1.17
go 1.18

require golang.org/x/sys v0.1.0
2 changes: 1 addition & 1 deletion user/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/moby/sys/user

go 1.17
go 1.18

require golang.org/x/sys v0.1.0