Merge pull request #2937 from andreaso/self-update-output-path-fix

Don't require `self-update --output` placeholder file
This commit is contained in:
rawtaz 2020-10-03 13:35:20 +02:00 committed by GitHub
commit bbeb439f41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View file

@ -0,0 +1,9 @@
Bugfix: Don't require `self-update --output` placeholder file
`restic self-update --output /path/to/new-restic` used to require that
new-restic was an existing file, to be overwritten. Now it's possible
to download an updated restic binary to a new path, without first
having to create a placeholder file.
https://github.com/restic/restic/issues/2491
https://github.com/restic/restic/pull/2937

View file

@ -4,6 +4,7 @@ package main
import (
"os"
"path/filepath"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/selfupdate"
@ -56,11 +57,18 @@ func runSelfUpdate(opts SelfUpdateOptions, gopts GlobalOptions, args []string) e
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)
dirname := filepath.Dir(opts.Output)
di, err := os.Lstat(dirname)
if err != nil {
return err
}
if !di.Mode().IsDir() {
return errors.Fatalf("output parent path %v is not a directory, use --output to specify a different file path", dirname)
}
} else {
if !fi.Mode().IsRegular() {
return errors.Fatalf("output path %v is not a normal file, use --output to specify a different file path", opts.Output)
}
}
Printf("writing restic to %v\n", opts.Output)