1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Update utils.go to not enforce extra constraints on the kernel "flavor" (such as being integral or even comparable one to another)

This is especially to fix the current docker on kernels such as gentoo-sources, where the "flavor" is the string "gentoo", and that obviously fails to be converted to an integer.
This commit is contained in:
Tianon Gravi 2013-04-21 19:19:38 -06:00
parent 965e8a02d2
commit 1f65c6bf4c
2 changed files with 23 additions and 31 deletions

View file

@ -399,10 +399,10 @@ func CopyEscapable(dst io.Writer, src io.ReadCloser) (written int64, err error)
} }
type KernelVersionInfo struct { type KernelVersionInfo struct {
Kernel int Kernel int
Major int Major int
Minor int Minor int
Specific int Flavor string
} }
// FIXME: this doens't build on Darwin // FIXME: this doens't build on Darwin
@ -445,21 +445,18 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
return nil, err return nil, err
} }
specific, err := strconv.Atoi(strings.Split(tmp[1], "-")[0]) flavor := tmp[1]
if err != nil {
return nil, err
}
return &KernelVersionInfo{ return &KernelVersionInfo{
Kernel: kernel, Kernel: kernel,
Major: major, Major: major,
Minor: minor, Minor: minor,
Specific: specific, Flavor: flavor,
}, nil }, nil
} }
func (k *KernelVersionInfo) String() string { func (k *KernelVersionInfo) String() string {
return fmt.Sprintf("%d.%d.%d-%d", k.Kernel, k.Major, k.Minor, k.Specific) return fmt.Sprintf("%d.%d.%d-%s", k.Kernel, k.Major, k.Minor, k.Flavor)
} }
// Compare two KernelVersionInfo struct. // Compare two KernelVersionInfo struct.
@ -483,11 +480,6 @@ func CompareKernelVersion(a, b *KernelVersionInfo) int {
return 1 return 1
} }
if a.Specific < b.Specific {
return -1
} else if a.Specific > b.Specific {
return 1
}
return 0 return 0
} }

View file

@ -237,27 +237,27 @@ func assertKernelVersion(t *testing.T, a, b *KernelVersionInfo, result int) {
func TestCompareKernelVersion(t *testing.T) { func TestCompareKernelVersion(t *testing.T) {
assertKernelVersion(t, assertKernelVersion(t,
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
0) 0)
assertKernelVersion(t, assertKernelVersion(t,
&KernelVersionInfo{Kernel: 2, Major: 6, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 2, Major: 6, Minor: 0},
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
-1) -1)
assertKernelVersion(t, assertKernelVersion(t,
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
&KernelVersionInfo{Kernel: 2, Major: 6, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 2, Major: 6, Minor: 0},
1) 1)
assertKernelVersion(t, assertKernelVersion(t,
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Flavor: "0"},
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 16}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Flavor: "16"},
-1) 0)
assertKernelVersion(t, assertKernelVersion(t,
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 5, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 5},
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0},
1) 1)
assertKernelVersion(t, assertKernelVersion(t,
&KernelVersionInfo{Kernel: 3, Major: 0, Minor: 20, Specific: 25}, &KernelVersionInfo{Kernel: 3, Major: 0, Minor: 20, Flavor: "25"},
&KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Specific: 0}, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0, Flavor: "0"},
-1) -1)
} }