mirror of
https://github.com/rclone/rclone.git
synced 2025-08-16 16:41:34 +02:00
ftp,sftp: fix docs for usernames
- factor env.CurrentUser out of backend/sftp - Use env.CurrentUser in ftp and sftp - fix docs to have correct username
This commit is contained in:
20
lib/env/env.go
vendored
20
lib/env/env.go
vendored
@ -3,6 +3,7 @@ package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
)
|
||||
@ -24,3 +25,22 @@ func ShellExpand(s string) string {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// CurrentUser finds the current user name or "" if not found
|
||||
func CurrentUser() (userName string) {
|
||||
userName = os.Getenv("USER")
|
||||
// If we are making docs just use $USER
|
||||
if userName == "$USER" {
|
||||
return userName
|
||||
}
|
||||
// Try reading using the OS
|
||||
usr, err := user.Current()
|
||||
if err == nil {
|
||||
return usr.Username
|
||||
}
|
||||
// Fall back to reading $USER then $LOGNAME
|
||||
if userName != "" {
|
||||
return userName
|
||||
}
|
||||
return os.Getenv("LOGNAME")
|
||||
}
|
||||
|
Reference in New Issue
Block a user