mirror of
https://github.com/kopia/kopia.git
synced 2026-02-01 18:23:36 -05:00
Removed Warning, Notify and Fatal: * `Warning` => `Error` or `Info` * `Notify` => `Info` * `Fatal` was never used. Note that --log-level=warning is still supported for backwards compatibility, but it is the same as --log-level=error. Co-authored-by: Julio López <julio+gh@kasten.io>
44 lines
828 B
Go
44 lines
828 B
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/user"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// GetDefaultUserName returns default username.
|
|
func GetDefaultUserName(ctx context.Context) string {
|
|
currentUser, err := user.Current()
|
|
if err != nil {
|
|
log(ctx).Errorf("Cannot determine current user: %s", err)
|
|
return "nobody"
|
|
}
|
|
|
|
u := currentUser.Username
|
|
|
|
if runtime.GOOS == "windows" {
|
|
if p := strings.Index(u, "\\"); p >= 0 {
|
|
// On Windows ignore domain name.
|
|
u = u[p+1:]
|
|
}
|
|
}
|
|
|
|
return u
|
|
}
|
|
|
|
// GetDefaultHostName returns default hostname.
|
|
func GetDefaultHostName(ctx context.Context) string {
|
|
hostname, err := os.Hostname()
|
|
if err != nil {
|
|
log(ctx).Errorf("Unable to determine hostname: %s\n", err)
|
|
return "nohost"
|
|
}
|
|
|
|
// Normalize hostname.
|
|
hostname = strings.ToLower(strings.Split(hostname, ".")[0])
|
|
|
|
return hostname
|
|
}
|