refactor: cleanup comments

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

Former-commit-id: 09c20fe153894ff9f7d076d7470b015240c2e0ea [formerly 5d924777fe9ceb19a894eb8d450ab6b47a99d1e6] [formerly c4e99a1cee5b217f76cf2db05827c115ee1ef45c [formerly cc79548206]]
Former-commit-id: d3504f478810703708c751c3fefbfec11453d8c5 [formerly 205fbb1cef0aebedb15c27d7c73316262583b3cd]
Former-commit-id: 4339b62732ce10bfabe4193dd81a07a741c1ecf2
This commit is contained in:
Henrique Dias 2019-04-20 14:22:19 +01:00
parent fa86894550
commit 243b12d4c2

View File

@ -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
} }