From 7d0f2eaf24cffe6f45d7980a39791a08f5ba4d8e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 14 Oct 2018 17:29:19 +0200 Subject: [PATCH] self-update: Use correct path to restic binary Closes #2041 --- cmd/restic/cmd_self_update.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cmd_self_update.go b/cmd/restic/cmd_self_update.go index 00d91b294..c7a29ac86 100644 --- a/cmd/restic/cmd_self_update.go +++ b/cmd/restic/cmd_self_update.go @@ -1,4 +1,4 @@ -// +build selfupdate +// xbuild selfupdate package main @@ -36,10 +36,30 @@ func init() { cmdRoot.AddCommand(cmdSelfUpdate) 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 { + 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, Verbosef) if err != nil { return errors.Fatalf("unable to update restic: %v", err)