Skip to content

Commit

Permalink
feat: allows the user to decide whether to continue the installation …
Browse files Browse the repository at this point in the history
…if the checksum file does not exist. voidint#60
  • Loading branch information
voidint committed Jun 6, 2022
1 parent 7703682 commit f6e7cb9
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ func install(ctx *cli.Context) (err error) {
pkg = pkgs[0]
}

var checksumNotFound, skipChecksum bool
if pkg.Checksum == "" && pkg.ChecksumURL == "" {
checksumNotFound = true
menu := wmenu.NewMenu("Checksum file not found, do you want to continue?")
menu.IsYesNo(wmenu.DefN)
menu.Action(func(opts []wmenu.Opt) error {
skipChecksum = opts[0].Value.(string) == "yes"
return nil
})
if err = menu.Run(); err != nil {
return cli.Exit(errstring(err), 1)
}
}
if checksumNotFound && !skipChecksum {
return
}

var ext string
if runtime.GOOS == "windows" {
ext = "zip"
Expand All @@ -93,19 +110,25 @@ func install(ctx *cli.Context) (err error) {
return cli.Exit(errstring(err), 1)
}

fmt.Println("Computing checksum with", pkg.Algorithm)
if err = pkg.VerifyChecksum(filename); err != nil {
return cli.Exit(errstring(err), 1)
if !skipChecksum {
fmt.Println("Computing checksum with", pkg.Algorithm)
if err = pkg.VerifyChecksum(filename); err != nil {
return cli.Exit(errstring(err), 1)
}
fmt.Println("Checksums matched")
}

} else {
// 本地存在安装包,检查校验和。
fmt.Println("Computing checksum with", pkg.Algorithm)
if err = pkg.VerifyChecksum(filename); err != nil {
_ = os.Remove(filename)
return cli.Exit(errstring(err), 1)
if !skipChecksum {
// 本地存在安装包,检查校验和。
fmt.Println("Computing checksum with", pkg.Algorithm)
if err = pkg.VerifyChecksum(filename); err != nil {
_ = os.Remove(filename)
return cli.Exit(errstring(err), 1)
}
fmt.Println("Checksums matched")
}
}
fmt.Println("Checksums matched")

// 删除可能存在的历史垃圾文件
_ = os.RemoveAll(filepath.Join(versionsDir, "go"))
Expand Down

0 comments on commit f6e7cb9

Please sign in to comment.