mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 19:38:57 +00:00
Merge pull request 2042 from restic/fix-2041
self-update: fix path to output file
This commit is contained in:
commit
7236635cc1
@ -1,4 +1,4 @@
|
|||||||
// +build selfupdate
|
// xbuild selfupdate
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -36,16 +36,38 @@ func init() {
|
|||||||
cmdRoot.AddCommand(cmdSelfUpdate)
|
cmdRoot.AddCommand(cmdSelfUpdate)
|
||||||
|
|
||||||
flags := cmdSelfUpdate.Flags()
|
flags := cmdSelfUpdate.Flags()
|
||||||
flags.StringVar(&selfUpdateOptions.Output, "output", os.Args[0], "Save the downloaded file as `filename`")
|
flags.StringVar(&selfUpdateOptions.Output, "output", "", "Save the downloaded file as `filename` (default: running binary itself)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func runSelfUpdate(opts SelfUpdateOptions, gopts GlobalOptions, args []string) error {
|
func runSelfUpdate(opts SelfUpdateOptions, gopts GlobalOptions, args []string) error {
|
||||||
v, err := selfupdate.DownloadLatestStableRelease(gopts.ctx, opts.Output, Verbosef)
|
if opts.Output == "" {
|
||||||
|
file, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "unable to find executable")
|
||||||
|
}
|
||||||
|
|
||||||
|
opts.Output = file
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Lstat(opts.Output)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fi.Mode().IsRegular() {
|
||||||
|
return errors.Errorf("output file %v is not a normal file, use --output to specify a different file", opts.Output)
|
||||||
|
}
|
||||||
|
|
||||||
|
Printf("writing restic to %v\n", opts.Output)
|
||||||
|
|
||||||
|
v, err := selfupdate.DownloadLatestStableRelease(gopts.ctx, opts.Output, version, Verbosef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Fatalf("unable to update restic: %v", err)
|
return errors.Fatalf("unable to update restic: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v != version {
|
||||||
Printf("successfully updated restic to version %v\n", v)
|
Printf("successfully updated restic to version %v\n", v)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func extractToFile(buf []byte, filename, target string, printf func(string, ...i
|
|||||||
// DownloadLatestStableRelease downloads the latest stable released version of
|
// DownloadLatestStableRelease downloads the latest stable released version of
|
||||||
// restic and saves it to target. It returns the version string for the newest
|
// restic and saves it to target. It returns the version string for the newest
|
||||||
// version. The function printf is used to print progress information.
|
// version. The function printf is used to print progress information.
|
||||||
func DownloadLatestStableRelease(ctx context.Context, target string, printf func(string, ...interface{})) (version string, err error) {
|
func DownloadLatestStableRelease(ctx context.Context, target, currentVersion string, printf func(string, ...interface{})) (version string, err error) {
|
||||||
if printf == nil {
|
if printf == nil {
|
||||||
printf = func(string, ...interface{}) {}
|
printf = func(string, ...interface{}) {}
|
||||||
}
|
}
|
||||||
@ -118,6 +118,11 @@ func DownloadLatestStableRelease(ctx context.Context, target string, printf func
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rel.Version == currentVersion {
|
||||||
|
printf("restic is up to date\n")
|
||||||
|
return currentVersion, nil
|
||||||
|
}
|
||||||
|
|
||||||
printf("latest version is %v\n", rel.Version)
|
printf("latest version is %v\n", rel.Version)
|
||||||
|
|
||||||
_, sha256sums, err := getGithubDataFile(ctx, rel.Assets, "SHA256SUMS", printf)
|
_, sha256sums, err := getGithubDataFile(ctx, rel.Assets, "SHA256SUMS", printf)
|
||||||
|
Loading…
Reference in New Issue
Block a user