From a716dc25339719bf9415bb562bfb990505e34255 Mon Sep 17 00:00:00 2001 From: Carl Edquist Date: Thu, 6 Oct 2022 00:27:21 -0500 Subject: [PATCH] config, terminal: move PasswordPromptOutput from config to terminal First, move this variable in order to avoid circular imports between config and terminal. (config already depends on terminal.) But also, it seems PasswordPromptOutput conceptually fits well in terminal, as the idea is for it to store the output for the terminal. --- fs/config/crypt.go | 3 --- fs/config/ui.go | 4 ++-- fs/log/redirect_stderr_unix.go | 4 ++-- lib/terminal/terminal.go | 7 ++++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/config/crypt.go b/fs/config/crypt.go index 6792811dc..805eecf66 100644 --- a/fs/config/crypt.go +++ b/fs/config/crypt.go @@ -26,9 +26,6 @@ var ( // When nil, no encryption will be used for saving. configKey []byte - // PasswordPromptOutput is output of prompt for password - PasswordPromptOutput = os.Stderr - // PassConfigKeyForDaemonization if set to true, the configKey // is obscured with obscure.Obscure and saved to a temp file // when it is calculated from the password. The path of that diff --git a/fs/config/ui.go b/fs/config/ui.go index 60b5b3bc6..8e55c1ee4 100644 --- a/fs/config/ui.go +++ b/fs/config/ui.go @@ -716,9 +716,9 @@ func checkPassword(password string) (string, error) { // GetPassword asks the user for a password with the prompt given. func GetPassword(prompt string) string { - _, _ = fmt.Fprintln(PasswordPromptOutput, prompt) + _, _ = fmt.Fprintln(terminal.PasswordPromptOutput, prompt) for { - _, _ = fmt.Fprint(PasswordPromptOutput, "password:") + _, _ = fmt.Fprint(terminal.PasswordPromptOutput, "password:") password := ReadPassword() password, err := checkPassword(password) if err == nil { diff --git a/fs/log/redirect_stderr_unix.go b/fs/log/redirect_stderr_unix.go index e0b8e4eca..5e3b66cd6 100644 --- a/fs/log/redirect_stderr_unix.go +++ b/fs/log/redirect_stderr_unix.go @@ -9,7 +9,7 @@ import ( "log" "os" - "github.com/rclone/rclone/fs/config" + "github.com/rclone/rclone/lib/terminal" "golang.org/x/sys/unix" ) @@ -19,7 +19,7 @@ func redirectStderr(f *os.File) { if err != nil { log.Fatalf("Failed to duplicate stderr: %v", err) } - config.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt") + terminal.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt") err = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd())) if err != nil { log.Fatalf("Failed to redirect stderr to file: %v", err) diff --git a/lib/terminal/terminal.go b/lib/terminal/terminal.go index f193eb767..09b05ec59 100644 --- a/lib/terminal/terminal.go +++ b/lib/terminal/terminal.go @@ -8,8 +8,6 @@ import ( "runtime" "sync" - "github.com/rclone/rclone/fs/config" - colorable "github.com/mattn/go-colorable" ) @@ -70,12 +68,15 @@ const ( var ( // make sure that start is only called once once sync.Once + + // PasswordPromptOutput is output of prompt for password + PasswordPromptOutput = os.Stderr ) // Start the terminal - must be called before use func Start() { once.Do(func() { - f := config.PasswordPromptOutput + f := PasswordPromptOutput if !IsTerminal(int(f.Fd())) { // If output is not a tty then remove escape codes Out = colorable.NewNonColorable(f)