-
Notifications
You must be signed in to change notification settings - Fork 440
/
check.go
42 lines (36 loc) · 966 Bytes
/
check.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
package conf
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
utils "github.com/alibaba/MongoShake/v2/common"
)
// read the given file and parse the fcv do comparison
func CheckFcv(file string, fcv int) (int, error) {
// read line by line and parse the version
f, err := os.Open(file)
if err != nil {
return -1, err
}
scanner := bufio.NewScanner(f)
versionName := "conf.version"
version := 0
for scanner.Scan() {
field := strings.Split(scanner.Text(), "=")
if len(field) >= 2 && strings.HasPrefix(field[0], versionName) {
if value, err := strconv.Atoi(strings.Trim(field[1], " ")); err != nil {
return 0, fmt.Errorf("illegal value[%v]", field[1])
} else {
version = value
break
}
}
}
if version < fcv {
return version, fmt.Errorf("current required configuration version[%v] > input[%v], please upgrade MongoShake to version >= %v",
fcv, version, utils.LowestConfigurationVersion[fcv])
}
return version, nil
}