-
Notifications
You must be signed in to change notification settings - Fork 69
/
sort.go
50 lines (43 loc) · 1.07 KB
/
sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package zfs
import (
"strconv"
)
type clonesCreateDesc []Dataset
func (list clonesCreateDesc) Less(i, j int) bool {
_, oki := list[i].Properties[DatasetNumProps+1000]
_, okj := list[i].Properties[DatasetNumProps+1000]
if oki && okj {
unixti, err := strconv.ParseInt(
list[i].Properties[DatasetNumProps+1000].Value, 10, 64)
if err != nil {
panic(err)
}
unixtj, err := strconv.ParseInt(
list[j].Properties[DatasetNumProps+1000].Value, 10, 64)
if err != nil {
panic(err)
}
if unixti != unixtj {
return unixti > unixtj
}
}
// if we have two datasets created from same snapshot
// any of them will do, but we will go for most recent
unixti, err := strconv.ParseInt(
list[i].Properties[DatasetPropCreateTXG].Value, 10, 64)
if err != nil {
panic(err)
}
unixtj, err := strconv.ParseInt(
list[j].Properties[DatasetPropCreateTXG].Value, 10, 64)
if err != nil {
panic(err)
}
return unixti > unixtj
}
func (list clonesCreateDesc) Swap(i, j int) {
list[i], list[j] = list[j], list[i]
}
func (list clonesCreateDesc) Len() int {
return len(list)
}