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

Merge pull request #454 from tianon/master

Update utils.go to not enforce extra constraints on the kernel "flavor" (such as being integral or even comparable one to another)
This commit is contained in:
Guillaume J. Charmes 2013-04-22 08:02:42 -07:00
commit 2ced94b414
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 {
Kernel int
Major int
Minor int
Specific int
Kernel int
Major int
Minor int
Flavor string
}
// FIXME: this doens't build on Darwin
@ -445,21 +445,18 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
return nil, err
}
specific, err := strconv.Atoi(strings.Split(tmp[1], "-")[0])
if err != nil {
return nil, err
}
flavor := tmp[1]
return &KernelVersionInfo{
Kernel: kernel,
Major: major,
Minor: minor,
Specific: specific,
Kernel: kernel,
Major: major,
Minor: minor,
Flavor: flavor,
}, nil
}
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.
@ -483,11 +480,6 @@ func CompareKernelVersion(a, b *KernelVersionInfo) int {
return 1
}
if a.Specific < b.Specific {
return -1
} else if a.Specific > b.Specific {
return 1
}
return 0
}

View file

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