Skip to content

Commit 253d9e4

Browse files
Gustedlunny6543
authored
Remove unnecassary calls to filepath.Join (#17608)
- Partialy resolvess #17596 - Resolves `badCall` errors from go-critic `badCall: suspicious Join on 1 argument` - When only 1 argument is passed into `filepath.Join`, it won't do anything special other than `filepath.Clean(...)` will be applied over it. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
1 parent 562785e commit 253d9e4

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

modules/repository/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
154154
count := 0
155155

156156
// We're going to iterate by pagesize.
157-
root := filepath.Join(setting.RepoRootPath)
157+
root := filepath.Clean(setting.RepoRootPath)
158158
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
159159
if err != nil {
160160
return err

routers/web/user/setting/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
2727
action := ctx.FormString("action")
2828

2929
ctxUser := ctx.User
30-
root := filepath.Join(models.UserPath(ctxUser.LowerName))
30+
root := models.UserPath(ctxUser.LowerName)
3131

3232
// check not a repo
3333
has, err := models.IsRepositoryExist(ctxUser, dir)

routers/web/user/setting/profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func Repos(ctx *context.Context) {
250250
repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum)
251251
repos := map[string]*models.Repository{}
252252
// We're going to iterate by pagesize.
253-
root := filepath.Join(models.UserPath(ctxUser.Name))
253+
root := models.UserPath(ctxUser.Name)
254254
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
255255
if err != nil {
256256
if os.IsNotExist(err) {

services/pull/merge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
275275
filepath.Join(tmpBasePath, ".git", "rebase-merge", "stopped-sha"), // Git >= 2.26
276276
}
277277
for _, failingCommitPath := range failingCommitPaths {
278-
if _, statErr := os.Stat(filepath.Join(failingCommitPath)); statErr == nil {
279-
commitShaBytes, readErr := os.ReadFile(filepath.Join(failingCommitPath))
278+
if _, statErr := os.Stat(failingCommitPath); statErr == nil {
279+
commitShaBytes, readErr := os.ReadFile(failingCommitPath)
280280
if readErr != nil {
281281
// Abandon this attempt to handle the error
282282
log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())

0 commit comments

Comments
 (0)