summaryrefslogtreecommitdiff
path: root/cmd/restic/global.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/restic/global.go')
-rw-r--r--cmd/restic/global.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/cmd/restic/global.go b/cmd/restic/global.go
index acff7ada6..1278cb4f0 100644
--- a/cmd/restic/global.go
+++ b/cmd/restic/global.go
@@ -1,6 +1,7 @@
package main
import (
+ "bufio"
"context"
"fmt"
"io"
@@ -37,7 +38,7 @@ import (
"os/exec"
)
-var version = "0.9.4"
+var version = "0.9.5"
// TimeFormat is the format used for all timestamps printed by restic.
const TimeFormat = "2006-01-02 15:04:05"
@@ -273,15 +274,10 @@ func resolvePassword(opts GlobalOptions) (string, error) {
// readPassword reads the password from the given reader directly.
func readPassword(in io.Reader) (password string, err error) {
- buf := make([]byte, 1000)
- n, err := io.ReadFull(in, buf)
- buf = buf[:n]
+ sc := bufio.NewScanner(in)
+ sc.Scan()
- if err != nil && errors.Cause(err) != io.ErrUnexpectedEOF {
- return "", errors.Wrap(err, "ReadFull")
- }
-
- return strings.TrimRight(string(buf), "\r\n"), nil
+ return sc.Text(), errors.Wrap(err, "Scan")
}
// readPasswordTerminal reads the password from the given reader which must be a
@@ -336,13 +332,15 @@ func ReadPasswordTwice(gopts GlobalOptions, prompt1, prompt2 string) (string, er
if err != nil {
return "", err
}
- pw2, err := ReadPassword(gopts, prompt2)
- if err != nil {
- return "", err
- }
+ if stdinIsTerminal() {
+ pw2, err := ReadPassword(gopts, prompt2)
+ if err != nil {
+ return "", err
+ }
- if pw1 != pw2 {
- return "", errors.Fatal("passwords do not match")
+ if pw1 != pw2 {
+ return "", errors.Fatal("passwords do not match")
+ }
}
return pw1, nil
@@ -377,7 +375,7 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) {
return nil, err
}
- if stdoutIsTerminal() {
+ if stdoutIsTerminal() && !opts.JSON {
id := s.Config().ID
if len(id) > 8 {
id = id[:8]