mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 18:04:55 +01:00
log: password prompt output fixed for unix - partially fixes #2220
This commit is contained in:
parent
d7ac4ca44e
commit
ce109ed9c0
@ -74,6 +74,9 @@ var (
|
|||||||
// Key to use for password en/decryption.
|
// Key to use for password en/decryption.
|
||||||
// When nil, no encryption will be used for saving.
|
// When nil, no encryption will be used for saving.
|
||||||
configKey []byte
|
configKey []byte
|
||||||
|
|
||||||
|
// output of prompt for password
|
||||||
|
PasswordPromptOutput = os.Stderr
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -287,9 +290,9 @@ func checkPassword(password string) (string, error) {
|
|||||||
|
|
||||||
// GetPassword asks the user for a password with the prompt given.
|
// GetPassword asks the user for a password with the prompt given.
|
||||||
func GetPassword(prompt string) string {
|
func GetPassword(prompt string) string {
|
||||||
_, _ = fmt.Fprintln(os.Stderr, prompt)
|
_, _ = fmt.Fprintln(PasswordPromptOutput, prompt)
|
||||||
for {
|
for {
|
||||||
_, _ = fmt.Fprint(os.Stderr, "password:")
|
_, _ = fmt.Fprint(PasswordPromptOutput, "password:")
|
||||||
password := ReadPassword()
|
password := ReadPassword()
|
||||||
password, err := checkPassword(password)
|
password, err := checkPassword(password)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -8,12 +8,19 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/ncw/rclone/fs/config"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// redirectStderr to the file passed in
|
// redirectStderr to the file passed in
|
||||||
func redirectStderr(f *os.File) {
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Failed to redirect stderr to file: %v", err)
|
log.Fatalf("Failed to redirect stderr to file: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user