!186 修改fastscan版本匹配算法

Merge pull request !186 from 宋帮诚晋/master
This commit is contained in:
宋帮诚晋 2023-03-08 02:40:22 +00:00 committed by Gitee
commit 10df87f98c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 18 additions and 22 deletions

Binary file not shown.

View File

@ -9,6 +9,8 @@ import (
"strings"
"bytes"
"os/exec"
"strconv"
"regexp"
// "reflect"
)
@ -33,6 +35,17 @@ var (
version1 = 1
version2 = 2
)
func StringStrip(str string) int {
if str == "" {
return 0
}
str = strings.TrimSpace(str)
reg := regexp.MustCompile(`[^\d]`)
result:=reg.ReplaceAllString(str, "")
result1,err:=strconv.Atoi(result)
checkerr(err)
return result1
}
func StrTrimSpace(v1str,v2str string )(v1,v2 string ){
v1=strings.TrimSpace(v1str)
v2=strings.TrimSpace(v2str)
@ -40,12 +53,13 @@ func StrTrimSpace(v1str,v2str string )(v1,v2 string ){
}
func comparSlice(v1slice,v2slice []string )int{
for index,_ :=range v1slice{
if v1slice[index] > v2slice[index]{
fmt.Println(1111,v1slice[index],v2slice[index])
// fmt.Printf("%T",v1slice[index])
v1sliceInt:=StringStrip(v1slice[index])
v2sliceInt:=StringStrip(v2slice[index])
if v1sliceInt > v2sliceInt{
return version1
}
if v1slice[index] < v2slice[index]{
fmt.Println(v1slice[index],v2slice[index])
if v1sliceInt < v2sliceInt{
return version2
}
if len(v1slice)-1 == index {
@ -176,8 +190,6 @@ func PushCompareVersion(cve_no string,dpkgInfoStr string,ubuntu_v10_1_edition st
}
v2 := strings.ReplaceAll(ubuntu_v10_1_edition, "ubuntu", ".")
v2 = strings.ReplaceAll(v2, "kylin", ".")
v1="2.2.10-3.2"
v2="2.2.8-1.1"
result=compareStrVer(v1,v2)
return result

View File

@ -1,16 +0,0 @@
package main
import (
"fmt"
"strings"
)
func main() {
s:="2.0.2kylin0.2k3"
i:=strings.LastIndex(s, "c") //9
if i != -1{
s = string([]byte(s)[0:i])
fmt.Println(s)
}else{
fmt.Println(2)
}
}