File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -75,27 +75,31 @@ const (
75
75
76
76
var cache struct {
77
77
sync.Once
78
- u * user.User
79
- err error
80
- warning string
78
+ u * user.User
79
+ err error
80
+ warnings [] string
81
81
}
82
82
83
83
func LimaUser (warn bool ) (* user.User , error ) {
84
+ cache .warnings = []string {}
84
85
cache .Do (func () {
85
86
cache .u , cache .err = user .Current ()
86
87
if cache .err == nil {
87
88
// `useradd` only allows user and group names matching the following pattern:
88
89
// (it allows a trailing '$', but it feels prudent to map those to the fallback user as well)
89
90
validName := "^[a-z_][a-z0-9_-]*$"
90
91
if ! regexp .MustCompile (validName ).Match ([]byte (cache .u .Username )) {
91
- cache . warning = fmt .Sprintf ("local user %q is not a valid Linux username (must match %q); using %q username instead" ,
92
+ warning : = fmt .Sprintf ("local user %q is not a valid Linux username (must match %q); using %q username instead" ,
92
93
cache .u .Username , validName , fallbackUser )
94
+ cache .warnings = append (cache .warnings , warning )
93
95
cache .u .Username = fallbackUser
94
96
}
95
97
}
96
98
})
97
- if warn && cache .warning != "" {
98
- logrus .Warn (cache .warning )
99
+ if warn && len (cache .warnings ) > 0 {
100
+ for _ , warning := range cache .warnings {
101
+ logrus .Warn (warning )
102
+ }
99
103
}
100
104
return cache .u , cache .err
101
105
}
You can’t perform that action at this time.
0 commit comments