From 711194276cf28e112b3ca09b0100bbffc773ef5d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 21 Sep 2025 18:16:48 +0200 Subject: [PATCH] remove unused printer from ReadPassword --- cmd/restic/cmd_copy.go | 2 +- cmd/restic/cmd_init.go | 5 ++--- cmd/restic/cmd_key_add.go | 7 +++---- cmd/restic/cmd_key_passwd.go | 2 +- cmd/restic/global.go | 10 +++++----- cmd/restic/global_test.go | 5 ++--- cmd/restic/secondary_repo.go | 5 ++--- cmd/restic/secondary_repo_test.go | 5 ++--- 8 files changed, 18 insertions(+), 23 deletions(-) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 19bfe8679..9e772a6e9 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -69,7 +69,7 @@ func (opts *CopyOptions) AddFlags(f *pflag.FlagSet) { func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := ui.NewProgressPrinter(false, gopts.verbosity, term) - secondaryGopts, isFromRepo, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "destination", printer) + secondaryGopts, isFromRepo, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "destination") if err != nil { return err } diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 1858cd22c..c13b69e87 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -92,8 +92,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args [] gopts.password, err = ReadPasswordTwice(ctx, gopts, "enter password for new repository: ", - "enter password again: ", - printer) + "enter password again: ") if err != nil { return err } @@ -140,7 +139,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args [] func maybeReadChunkerPolynomial(ctx context.Context, opts InitOptions, gopts GlobalOptions, printer progress.Printer) (*chunker.Pol, error) { if opts.CopyChunkerParameters { - otherGopts, _, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "secondary", printer) + otherGopts, _, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "secondary") if err != nil { return nil, err } diff --git a/cmd/restic/cmd_key_add.go b/cmd/restic/cmd_key_add.go index 196c4a8de..455969d6e 100644 --- a/cmd/restic/cmd_key_add.go +++ b/cmd/restic/cmd_key_add.go @@ -70,7 +70,7 @@ func runKeyAdd(ctx context.Context, gopts GlobalOptions, opts KeyAddOptions, arg } func addKey(ctx context.Context, repo *repository.Repository, gopts GlobalOptions, opts KeyAddOptions, printer progress.Printer) error { - pw, err := getNewPassword(ctx, gopts, opts.NewPasswordFile, opts.InsecureNoPassword, printer) + pw, err := getNewPassword(ctx, gopts, opts.NewPasswordFile, opts.InsecureNoPassword) if err != nil { return err } @@ -93,7 +93,7 @@ func addKey(ctx context.Context, repo *repository.Repository, gopts GlobalOption // testKeyNewPassword is used to set a new password during integration testing. var testKeyNewPassword string -func getNewPassword(ctx context.Context, gopts GlobalOptions, newPasswordFile string, insecureNoPassword bool, printer progress.Printer) (string, error) { +func getNewPassword(ctx context.Context, gopts GlobalOptions, newPasswordFile string, insecureNoPassword bool) (string, error) { if testKeyNewPassword != "" { return testKeyNewPassword, nil } @@ -125,8 +125,7 @@ func getNewPassword(ctx context.Context, gopts GlobalOptions, newPasswordFile st return ReadPasswordTwice(ctx, newopts, "enter new password: ", - "enter password again: ", - printer) + "enter password again: ") } func switchToNewKeyAndRemoveIfBroken(ctx context.Context, repo *repository.Repository, key *repository.Key, pw string) error { diff --git a/cmd/restic/cmd_key_passwd.go b/cmd/restic/cmd_key_passwd.go index 5eacd11b3..98cdfc43f 100644 --- a/cmd/restic/cmd_key_passwd.go +++ b/cmd/restic/cmd_key_passwd.go @@ -65,7 +65,7 @@ func runKeyPasswd(ctx context.Context, gopts GlobalOptions, opts KeyPasswdOption } func changePassword(ctx context.Context, repo *repository.Repository, gopts GlobalOptions, opts KeyPasswdOptions, printer progress.Printer) error { - pw, err := getNewPassword(ctx, gopts, opts.NewPasswordFile, opts.InsecureNoPassword, printer) + pw, err := getNewPassword(ctx, gopts, opts.NewPasswordFile, opts.InsecureNoPassword) if err != nil { return err } diff --git a/cmd/restic/global.go b/cmd/restic/global.go index bcd7d52fc..cd17dccc7 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -230,7 +230,7 @@ func loadPasswordFromFile(pwdFile string) (string, error) { // ReadPassword reads the password from a password file, the environment // variable RESTIC_PASSWORD or prompts the user. If the context is canceled, // the function leaks the password reading goroutine. -func ReadPassword(ctx context.Context, gopts GlobalOptions, prompt string, printer progress.Printer) (string, error) { +func ReadPassword(ctx context.Context, gopts GlobalOptions, prompt string) (string, error) { if gopts.InsecureNoPassword { if gopts.password != "" { return "", errors.Fatal("--insecure-no-password must not be specified together with providing a password via a cli option or environment variable") @@ -257,13 +257,13 @@ func ReadPassword(ctx context.Context, gopts GlobalOptions, prompt string, print // ReadPasswordTwice calls ReadPassword two times and returns an error when the // passwords don't match. If the context is canceled, the function leaks the // password reading goroutine. -func ReadPasswordTwice(ctx context.Context, gopts GlobalOptions, prompt1, prompt2 string, printer progress.Printer) (string, error) { - pw1, err := ReadPassword(ctx, gopts, prompt1, printer) +func ReadPasswordTwice(ctx context.Context, gopts GlobalOptions, prompt1, prompt2 string) (string, error) { + pw1, err := ReadPassword(ctx, gopts, prompt1) if err != nil { return "", err } if gopts.term.InputIsTerminal() { - pw2, err := ReadPassword(ctx, gopts, prompt2, printer) + pw2, err := ReadPassword(ctx, gopts, prompt2) if err != nil { return "", err } @@ -330,7 +330,7 @@ func OpenRepository(ctx context.Context, gopts GlobalOptions, printer progress.P } for ; passwordTriesLeft > 0; passwordTriesLeft-- { - gopts.password, err = ReadPassword(ctx, gopts, "enter password for repository: ", printer) + gopts.password, err = ReadPassword(ctx, gopts, "enter password for repository: ") if ctx.Err() != nil { return nil, ctx.Err() } diff --git a/cmd/restic/global_test.go b/cmd/restic/global_test.go index de8275876..e8def7b94 100644 --- a/cmd/restic/global_test.go +++ b/cmd/restic/global_test.go @@ -8,7 +8,6 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/progress" ) func TestReadRepo(t *testing.T) { @@ -42,11 +41,11 @@ func TestReadRepo(t *testing.T) { func TestReadEmptyPassword(t *testing.T) { opts := GlobalOptions{InsecureNoPassword: true} - password, err := ReadPassword(context.TODO(), opts, "test", &progress.NoopPrinter{}) + password, err := ReadPassword(context.TODO(), opts, "test") rtest.OK(t, err) rtest.Equals(t, "", password, "got unexpected password") opts.password = "invalid" - _, err = ReadPassword(context.TODO(), opts, "test", &progress.NoopPrinter{}) + _, err = ReadPassword(context.TODO(), opts, "test") rtest.Assert(t, strings.Contains(err.Error(), "must not be specified together with providing a password via a cli option or environment variable"), "unexpected error message, got %v", err) } diff --git a/cmd/restic/secondary_repo.go b/cmd/restic/secondary_repo.go index 16c75f1ab..db4c93bad 100644 --- a/cmd/restic/secondary_repo.go +++ b/cmd/restic/secondary_repo.go @@ -5,7 +5,6 @@ import ( "os" "github.com/restic/restic/internal/errors" - "github.com/restic/restic/internal/ui/progress" "github.com/spf13/pflag" ) @@ -60,7 +59,7 @@ func (opts *secondaryRepoOptions) AddFlags(f *pflag.FlagSet, repoPrefix string, opts.PasswordCommand = os.Getenv("RESTIC_FROM_PASSWORD_COMMAND") } -func fillSecondaryGlobalOpts(ctx context.Context, opts secondaryRepoOptions, gopts GlobalOptions, repoPrefix string, printer progress.Printer) (GlobalOptions, bool, error) { +func fillSecondaryGlobalOpts(ctx context.Context, opts secondaryRepoOptions, gopts GlobalOptions, repoPrefix string) (GlobalOptions, bool, error) { if opts.Repo == "" && opts.RepositoryFile == "" && opts.LegacyRepo == "" && opts.LegacyRepositoryFile == "" { return GlobalOptions{}, false, errors.Fatal("Please specify a source repository location (--from-repo or --from-repository-file)") } @@ -116,7 +115,7 @@ func fillSecondaryGlobalOpts(ctx context.Context, opts secondaryRepoOptions, gop return GlobalOptions{}, false, err } } - dstGopts.password, err = ReadPassword(ctx, dstGopts, "enter password for "+repoPrefix+" repository: ", printer) + dstGopts.password, err = ReadPassword(ctx, dstGopts, "enter password for "+repoPrefix+" repository: ") if err != nil { return GlobalOptions{}, false, err } diff --git a/cmd/restic/secondary_repo_test.go b/cmd/restic/secondary_repo_test.go index 32206318a..c6837ada4 100644 --- a/cmd/restic/secondary_repo_test.go +++ b/cmd/restic/secondary_repo_test.go @@ -7,7 +7,6 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/progress" ) // TestFillSecondaryGlobalOpts tests valid and invalid data on fillSecondaryGlobalOpts-function @@ -166,7 +165,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) { // Test all valid cases for _, testCase := range validSecondaryRepoTestCases { - DstGOpts, isFromRepo, err := fillSecondaryGlobalOpts(context.TODO(), testCase.Opts, gOpts, "destination", &progress.NoopPrinter{}) + DstGOpts, isFromRepo, err := fillSecondaryGlobalOpts(context.TODO(), testCase.Opts, gOpts, "destination") rtest.OK(t, err) rtest.Equals(t, DstGOpts, testCase.DstGOpts) rtest.Equals(t, isFromRepo, testCase.FromRepo) @@ -174,7 +173,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) { // Test all invalid cases for _, testCase := range invalidSecondaryRepoTestCases { - _, _, err := fillSecondaryGlobalOpts(context.TODO(), testCase.Opts, gOpts, "destination", &progress.NoopPrinter{}) + _, _, err := fillSecondaryGlobalOpts(context.TODO(), testCase.Opts, gOpts, "destination") rtest.Assert(t, err != nil, "Expected error, but function did not return an error") } }