refactor(cmd/joj3): use filepath.Join
All checks were successful
submodules sync / sync (push) Successful in 41s
build / build (push) Successful in 1m26s
build / trigger-build-image (push) Successful in 8s

This commit is contained in:
张泊明518370910136 2024-10-29 05:43:40 -04:00
parent 34f1cbc711
commit 028fd11ab5
GPG Key ID: D47306D7062CDA9D

View File

@ -226,8 +226,7 @@ func parseMsg(confRoot, confName, msg, tag string) (
} }
slog.Info("conventional commit", "commit", conventionalCommit) slog.Info("conventional commit", "commit", conventionalCommit)
confRoot = filepath.Clean(confRoot) confRoot = filepath.Clean(confRoot)
confPath = filepath.Clean(fmt.Sprintf("%s/%s/%s", confPath = filepath.Join(confRoot, conventionalCommit.Scope, confName)
confRoot, conventionalCommit.Scope, confName))
relPath, err := filepath.Rel(confRoot, confPath) relPath, err := filepath.Rel(confRoot, confPath)
if err != nil { if err != nil {
return return
@ -289,8 +288,7 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
if err != nil { if err != nil {
slog.Error("parse msg", "error", err) slog.Error("parse msg", "error", err)
// fallback to conf file in conf root on parse error // fallback to conf file in conf root on parse error
confPath = filepath.Clean( confPath = filepath.Join(confRoot, fallbackConfName)
fmt.Sprintf("%s/%s", confRoot, fallbackConfName))
slog.Info("fallback to conf", "path", confPath) slog.Info("fallback to conf", "path", confPath)
} }
confStat, err = os.Stat(confPath) confStat, err = os.Stat(confPath)
@ -300,8 +298,7 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
} }
slog.Error("stat conf", "error", err) slog.Error("stat conf", "error", err)
// fallback to conf file in conf root on conf not exist // fallback to conf file in conf root on conf not exist
confPath = filepath.Clean( confPath = filepath.Join(confRoot, fallbackConfName)
fmt.Sprintf("%s/%s", confRoot, fallbackConfName))
slog.Info("fallback to conf", "path", confPath) slog.Info("fallback to conf", "path", confPath)
confStat, err = os.Stat(confPath) confStat, err = os.Stat(confPath)
if err != nil { if err != nil {