refactor: cleanup comments
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>pull/721/head
parent
b7fdcc3ee9
commit
cc79548206
|
@ -30,9 +30,9 @@ func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (s
|
||||||
|
|
||||||
fs := afero.NewBasePathFs(afero.NewOsFs(), serverRoot)
|
fs := afero.NewBasePathFs(afero.NewOsFs(), serverRoot)
|
||||||
|
|
||||||
//use the default auto create logic only if specific scope is not the default scope
|
// Use the default auto create logic only if specific scope is not the default scope
|
||||||
if userScope != settings.Defaults.Scope {
|
if userScope != settings.Defaults.Scope {
|
||||||
//try create the dir, for example: settings.Defaults.Scope == "." and userScope == "./foo"
|
// Try create the dir, for example: settings.Defaults.Scope == "." and userScope == "./foo"
|
||||||
if userScope != "." {
|
if userScope != "." {
|
||||||
err = fs.MkdirAll(userScope, os.ModePerm)
|
err = fs.MkdirAll(userScope, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -42,14 +42,14 @@ func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (s
|
||||||
return userScope, err
|
return userScope, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//clean username first
|
// Clean username first
|
||||||
username = cleanUsername(username)
|
username = cleanUsername(username)
|
||||||
if username == "" || username == "-" || username == "." {
|
if username == "" || username == "-" || username == "." {
|
||||||
log.Printf("create user: invalid user for home dir creation: [%s]", username)
|
log.Printf("create user: invalid user for home dir creation: [%s]", username)
|
||||||
return "", errors.New("invalid user for home dir creation")
|
return "", errors.New("invalid user for home dir creation")
|
||||||
}
|
}
|
||||||
|
|
||||||
//create default user dir
|
// Create default user dir
|
||||||
userHomeBase := settings.Defaults.Scope + string(os.PathSeparator) + "users"
|
userHomeBase := settings.Defaults.Scope + string(os.PathSeparator) + "users"
|
||||||
userHome := userHomeBase + string(os.PathSeparator) + username
|
userHome := userHomeBase + string(os.PathSeparator) + username
|
||||||
err = fs.MkdirAll(userHome, os.ModePerm)
|
err = fs.MkdirAll(userHome, os.ModePerm)
|
||||||
|
@ -62,10 +62,8 @@ func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (s
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanUsername(s string) string {
|
func cleanUsername(s string) string {
|
||||||
|
|
||||||
// Remove any trailing space to avoid ending on -
|
// Remove any trailing space to avoid ending on -
|
||||||
s = strings.Trim(s, " ")
|
s = strings.Trim(s, " ")
|
||||||
|
|
||||||
s = strings.Replace(s, "..", "", -1)
|
s = strings.Replace(s, "..", "", -1)
|
||||||
|
|
||||||
// Replace all characters which not in the list `0-9A-Za-z@_\-.` with a dash
|
// Replace all characters which not in the list `0-9A-Za-z@_\-.` with a dash
|
||||||
|
@ -73,6 +71,5 @@ func cleanUsername(s string) string {
|
||||||
|
|
||||||
// Remove any multiple dashes caused by replacements above
|
// Remove any multiple dashes caused by replacements above
|
||||||
s = dashes.ReplaceAllString(s, "-")
|
s = dashes.ReplaceAllString(s, "-")
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue