MCPcopy Index your code
hub / github.com/SummerSec/SpringExploit / confirmAndSelfUpdate

Function confirmAndSelfUpdate

cmd/commons/core/update2.go:39–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39func confirmAndSelfUpdate() {
40 latest, found, err := selfupdate.DetectLatest(info)
41 if err != nil {
42 log.Infoln("Error occurred while detecting version:", err)
43 return
44 }
45
46 v := semver.MustParse(version)
47 if !found || latest.Version.LTE(v) {
48 log.Infof("Current version is the latest version %s", version)
49 return
50 }
51
52 fmt.Print("Do you want to update to latest version ", latest.Version, "? (y/n): ")
53 input, err := bufio.NewReader(os.Stdin).ReadString('\n')
54 // 如果input 存在\r或者\n,则去掉
55 if stringsutil.HasSuffixAny(input, "\r\n", "\n", "\r") {
56 input = stringsutil.TrimSuffixAny(input, "\r\n", "\n", "\r")
57 }
58 if err != nil || (input != "y" && input != "n" && input != "Y" && input != "N") {
59 log.Println("Invalid input")
60 return
61 }
62 if input == "n" {
63 return
64 }
65
66 exe, err := os.Executable()
67 if err != nil {
68 log.Println("Could not locate executable path")
69 return
70 }
71 if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil {
72 log.Println("Error occurred while updating binary:", err)
73 return
74 }
75 log.Println("Successfully updated to version", latest.Version)
76}

Callers 2

ParseOptionsFunction · 0.85
RunMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected