selfupdate: obey --no-check-certificate flag
This patch makes sure we use our own HTTP transport when fetching the current rclone version. This allows it to use --no-check-certificate (and any other features of our own transport). See: https://forum.rclone.org/t/rclone-selfupdate-no-check-certificate-flag-not-work/37501
This commit is contained in:
parent
e82db0b7d5
commit
4471e6f258
2 changed files with 11 additions and 7 deletions
|
@ -68,13 +68,14 @@ var cmdSelfUpdate = &cobra.Command{
|
|||
"versionIntroduced": "v1.55",
|
||||
},
|
||||
Run: func(command *cobra.Command, args []string) {
|
||||
ctx := context.Background()
|
||||
cmd.CheckArgs(0, 0, command, args)
|
||||
if Opt.Package == "" {
|
||||
Opt.Package = "zip"
|
||||
}
|
||||
gotActionFlags := Opt.Stable || Opt.Beta || Opt.Output != "" || Opt.Version != "" || Opt.Package != "zip"
|
||||
if Opt.Check && !gotActionFlags {
|
||||
versionCmd.CheckVersion()
|
||||
versionCmd.CheckVersion(ctx)
|
||||
return
|
||||
}
|
||||
if Opt.Package != "zip" {
|
||||
|
@ -108,7 +109,7 @@ func GetVersion(ctx context.Context, beta bool, version string) (newVersion, sit
|
|||
|
||||
if version == "" {
|
||||
// Request the latest release number from the download site
|
||||
_, newVersion, _, err = versionCmd.GetVersion(siteURL + "/version.txt")
|
||||
_, newVersion, _, err = versionCmd.GetVersion(ctx, siteURL+"/version.txt")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
"github.com/rclone/rclone/cmd"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config/flags"
|
||||
"github.com/rclone/rclone/fs/fshttp"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -71,9 +73,10 @@ Or
|
|||
"versionIntroduced": "v1.33",
|
||||
},
|
||||
Run: func(command *cobra.Command, args []string) {
|
||||
ctx := context.Background()
|
||||
cmd.CheckArgs(0, 0, command, args)
|
||||
if check {
|
||||
CheckVersion()
|
||||
CheckVersion(ctx)
|
||||
} else {
|
||||
cmd.ShowVersion()
|
||||
}
|
||||
|
@ -89,8 +92,8 @@ func stripV(s string) string {
|
|||
}
|
||||
|
||||
// GetVersion gets the version available for download
|
||||
func GetVersion(url string) (v *semver.Version, vs string, date time.Time, err error) {
|
||||
resp, err := http.Get(url)
|
||||
func GetVersion(ctx context.Context, url string) (v *semver.Version, vs string, date time.Time, err error) {
|
||||
resp, err := fshttp.NewClient(ctx).Get(url)
|
||||
if err != nil {
|
||||
return v, vs, date, err
|
||||
}
|
||||
|
@ -114,7 +117,7 @@ func GetVersion(url string) (v *semver.Version, vs string, date time.Time, err e
|
|||
}
|
||||
|
||||
// CheckVersion checks the installed version against available downloads
|
||||
func CheckVersion() {
|
||||
func CheckVersion(ctx context.Context) {
|
||||
vCurrent, err := semver.NewVersion(stripV(fs.Version))
|
||||
if err != nil {
|
||||
fs.Errorf(nil, "Failed to parse version: %v", err)
|
||||
|
@ -122,7 +125,7 @@ func CheckVersion() {
|
|||
const timeFormat = "2006-01-02"
|
||||
|
||||
printVersion := func(what, url string) {
|
||||
v, vs, t, err := GetVersion(url + "version.txt")
|
||||
v, vs, t, err := GetVersion(ctx, url+"version.txt")
|
||||
if err != nil {
|
||||
fs.Errorf(nil, "Failed to get rclone %s version: %v", what, err)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue