From 243b12d4c25e56b26e0ba0c1e1582edca1c32ca6 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 20 Apr 2019 14:22:19 +0100 Subject: [PATCH] refactor: cleanup comments License: MIT Signed-off-by: Henrique Dias Former-commit-id: 09c20fe153894ff9f7d076d7470b015240c2e0ea [formerly 5d924777fe9ceb19a894eb8d450ab6b47a99d1e6] [formerly c4e99a1cee5b217f76cf2db05827c115ee1ef45c [formerly cc79548206209b236c62d4745e1e0920118d7b1d]] Former-commit-id: d3504f478810703708c751c3fefbfec11453d8c5 [formerly 205fbb1cef0aebedb15c27d7c73316262583b3cd] Former-commit-id: 4339b62732ce10bfabe4193dd81a07a741c1ecf2 --- settings/dir.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/settings/dir.go b/settings/dir.go index bd21d8cc..49389724 100644 --- a/settings/dir.go +++ b/settings/dir.go @@ -30,9 +30,9 @@ func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (s 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 { - //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 != "." { err = fs.MkdirAll(userScope, os.ModePerm) if err != nil { @@ -42,14 +42,14 @@ func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (s return userScope, err } - //clean username first + // Clean username first username = cleanUsername(username) if username == "" || username == "-" || username == "." { log.Printf("create user: invalid user for home dir creation: [%s]", username) 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" userHome := userHomeBase + string(os.PathSeparator) + username err = fs.MkdirAll(userHome, os.ModePerm) @@ -62,10 +62,8 @@ func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (s } func cleanUsername(s string) string { - // Remove any trailing space to avoid ending on - s = strings.Trim(s, " ") - s = strings.Replace(s, "..", "", -1) // 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 s = dashes.ReplaceAllString(s, "-") - return s }