Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

log: password prompt output fixed for unix - partially fixes #2220

Filip Bartodziejce109ed9c075
diff --git a/fs/config/config.go b/fs/config/config.go
index 3cdac4fe3..0341ccc54 100644
--- a/fs/config/config.go
+++ b/fs/config/config.go
@@ -74,6 +74,9 @@ var (
// Key to use for password en/decryption.
// When nil, no encryption will be used for saving.
configKey []byte
+
+ // output of prompt for password
+ PasswordPromptOutput = os.Stderr
)
func init() {
@@ -287,9 +290,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(os.Stderr, prompt)
+ _, _ = fmt.Fprintln(PasswordPromptOutput, prompt)
for {
- _, _ = fmt.Fprint(os.Stderr, "password:")
+ _, _ = fmt.Fprint(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 5c5967d9e..6f5c32a3f 100644
--- a/fs/log/redirect_stderr_unix.go
+++ b/fs/log/redirect_stderr_unix.go
@@ -8,12 +8,19 @@ import (
"log"
"os"
+ "github.com/ncw/rclone/fs/config"
+
"golang.org/x/sys/unix"
)
// redirectStderr to the file passed in
func redirectStderr(f *os.File) {
- err := unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
+ passPromptFd, err := unix.Dup(int(os.Stderr.Fd()))
+ if err != nil {
+ log.Fatalf("Failed to duplicate stderr: %v", err)
+ }
+ config.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)
}