Skip to content
Snippets Groups Projects
Commit 5247c3a1 authored by Bensong Liu's avatar Bensong Liu
Browse files

bug fix

parent ff1e65ed
No related branches found
No related tags found
No related merge requests found
...@@ -179,67 +179,73 @@ func decidePackageVersionRange(packageName, frameworkVersion string, indexJsons ...@@ -179,67 +179,73 @@ func decidePackageVersionRange(packageName, frameworkVersion string, indexJsons
func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, indexJsons_Login []string) (maxAvailableVersion, maxAvailableVersionUrl, maxAvailableVersionUrlLogin string) { func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, indexJsons_Login []string) (maxAvailableVersion, maxAvailableVersionUrl, maxAvailableVersionUrlLogin string) {
// The golang json parse library sucks. Prevent it from crashing // The golang json parse library sucks. Prevent it from crashing
// on a json syntax error. // on a json syntax error.
//
// This function is very ugly. Fucking go-json library and go exception.
defer func() {recover()} () defer func() {recover()} ()
for indexJson_currIndex, indexJson := range indexJsons { for indexJson_currIndex, indexJson := range indexJsons {
defer func() {recover()} () // try parse, skip this entry on error func () {
// entry = xml.findall("/items/[]/items/[]/catalogEntry") defer func() { recover() }() // try parse, skip this entry on error
// entry/version, entry/dependencyGroups[]/targetFramework, entry/../packageContent // entry = xml.findall("/items/[]/items/[]/catalogEntry")
// If there's no `targetFramework` in dependencyGroups, this package depends on specific version of parent package. it sucks. // entry/version, entry/dependencyGroups[]/targetFramework, entry/../packageContent
var j1 map[string]interface{} // If there's no `targetFramework` in dependencyGroups, this package depends on specific version of parent package. it sucks.
json.Unmarshal([]byte(indexJson), &j1) var j1 map[string]interface{}
j2 := j1["items"].([]interface{}) json.Unmarshal([]byte(indexJson), &j1)
for _, j2ele := range j2 { j2 := j1["items"].([]interface{})
defer func() {recover()} () // try parse, skip this entry on error for _, j2ele := range j2 {
j3 := j2ele.(map[string]interface{})["items"] j3 := j2ele.(map[string]interface{})["items"]
j4 := j3.([]interface{}) j4 := j3.([]interface{})
for _, jPkgVersionItem_ := range j4 { for _, jPkgVersionItem_ := range j4 {
defer func() {recover()} () // try parse, skip this entry on error func() {
jPkgVersionItem := jPkgVersionItem_.(map[string]interface{}) defer func() { recover() }() // try parse, skip this entry on error
jCatalogEntry := jPkgVersionItem["catalogEntry"].(map[string]interface{}) jPkgVersionItem := jPkgVersionItem_.(map[string]interface{})
myVersionText := jCatalogEntry["version"].(string) jCatalogEntry := jPkgVersionItem["catalogEntry"].(map[string]interface{})
// log.Println("DEBUG: reaching " + myVersionText) myVersionText := jCatalogEntry["version"].(string)
// log.Println("DEBUG: reaching " + myVersionText)
// Let's check if this version is ok
thisPkgVersionIsOk := false // Let's check if this version is ok
thisPkgVersionIsOk := false
if frameworkVersion != "" {
if j5, ok := jCatalogEntry["dependencyGroups"]; ok { if frameworkVersion != "" {
for _, j6 := range j5.([]interface{}) { if j5, ok := jCatalogEntry["dependencyGroups"]; ok {
j7 := j6.(map[string]interface{}) for _, j6 := range j5.([]interface{}) {
if j8, ok := j7["targetFramework"]; ok { j7 := j6.(map[string]interface{})
if frameworkVersion == netVersionNugetFormatToStandardFormat(j8.(string)) { if j8, ok := j7["targetFramework"]; ok {
thisPkgVersionIsOk = true if frameworkVersion == netVersionNugetFormatToStandardFormat(j8.(string)) {
break thisPkgVersionIsOk = true
break
}
} else {
// this pkgVersion has no targetFramework limitation.
thisPkgVersionIsOk = true
}
} }
} else { } else {
// this pkgVersion has no targetFramework limitation. // no dependencyGroups at all
thisPkgVersionIsOk = true thisPkgVersionIsOk = true
} }
} }
} else {
// no dependencyGroups at all
thisPkgVersionIsOk = true
}
}
if packageVersion != "" { if packageVersion != "" {
thisPkgVersionIsOk = packageVersion == myVersionText thisPkgVersionIsOk = packageVersion == myVersionText
} }
if thisPkgVersionIsOk { if thisPkgVersionIsOk {
// log.Println("DEBUG: good " + myVersionText) // log.Println("DEBUG: good " + myVersionText)
// This version is ok! Log it. // This version is ok! Log it.
myVersionUrl := jPkgVersionItem["packageContent"].(string) myVersionUrl := jPkgVersionItem["packageContent"].(string)
if version.CompareSimple(myVersionText, maxAvailableVersion) == 1 { if version.CompareSimple(myVersionText, maxAvailableVersion) == 1 {
// if left > right // if left > right
maxAvailableVersion = myVersionText maxAvailableVersion = myVersionText
maxAvailableVersionUrl = myVersionUrl maxAvailableVersionUrl = myVersionUrl
maxAvailableVersionUrlLogin = indexJsons_Login[indexJson_currIndex] maxAvailableVersionUrlLogin = indexJsons_Login[indexJson_currIndex]
} }
}
// log.Println("DEBUG: leaving " + myVersionText)
}() // catch exception and continue
} }
} }
} }() // catch exception and continue
} }
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment