Skip to content

Commit

Permalink
Simpify cmd_backup and cmd_init now we have the password in gopts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauline Middelink committed Jul 24, 2017
1 parent d5615a6 commit c95e2b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cmd/restic/cmd_backup.go
Expand Up @@ -249,7 +249,7 @@ func readBackupFromStdin(opts BackupOptions, gopts GlobalOptions, args []string)
return errors.Fatal("filename for backup from stdin must not be empty")
}

if gopts.password == "" && gopts.PasswordFile == "" {
if gopts.password == "" {
return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD")
}

Expand Down Expand Up @@ -322,8 +322,8 @@ func readLinesFromFile(filename string) ([]string, error) {
}

func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
if opts.FilesFrom == "-" && gopts.password == "" && gopts.PasswordFile == "" {
return errors.Fatal("no password; either use `--password-file` option or put the password into the RESTIC_PASSWORD environment variable")
if opts.FilesFrom == "-" && gopts.password == "" {
return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD")
}

fromfile, err := readLinesFromFile(opts.FilesFrom)
Expand Down
12 changes: 5 additions & 7 deletions cmd/restic/cmd_init.go
Expand Up @@ -34,13 +34,11 @@ func runInit(gopts GlobalOptions, args []string) error {
return errors.Fatalf("create backend at %s failed: %v\n", gopts.Repo, err)
}

if gopts.password == "" {
gopts.password, err = ReadPasswordTwice(gopts,
"enter password for new backend: ",
"enter password again: ")
if err != nil {
return err
}
gopts.password, err = ReadPasswordTwice(gopts,
"enter password for new backend: ",
"enter password again: ")
if err != nil {
return err
}

s := repository.New(be)
Expand Down
8 changes: 3 additions & 5 deletions cmd/restic/global.go
Expand Up @@ -307,11 +307,9 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) {

s := repository.New(be)

if opts.password == "" {
opts.password, err = ReadPassword(opts, "enter password for repository: ")
if err != nil {
return nil, err
}
opts.password, err = ReadPassword(opts, "enter password for repository: ")
if err != nil {
return nil, err
}

err = s.SearchKey(context.TODO(), opts.password, maxKeys)
Expand Down

0 comments on commit c95e2b0

Please sign in to comment.