]> source.dussan.org Git - gitea.git/commitdiff
Remove unnecassary calls to `filepath.Join` (#17608)
authorGusted <williamzijl7@hotmail.com>
Mon, 15 Nov 2021 06:02:53 +0000 (06:02 +0000)
committerGitHub <noreply@github.com>
Mon, 15 Nov 2021 06:02:53 +0000 (14:02 +0800)
- 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>
modules/repository/adopt.go
routers/web/user/setting/adopt.go
routers/web/user/setting/profile.go
services/pull/merge.go

index 21477ab7d771b5d74fdec556859fd1ab34f63fec..3d895ac4843c938294a2c8ed4ed4bfedeaecbb41 100644 (file)
@@ -154,7 +154,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
        count := 0
 
        // We're going to iterate by pagesize.
-       root := filepath.Join(setting.RepoRootPath)
+       root := filepath.Clean(setting.RepoRootPath)
        if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
                if err != nil {
                        return err
index e45a8a132465aee0d59216a2562e39a8399fc523..2caccb69a5012301703cf77639a2f811557f9f25 100644 (file)
@@ -27,7 +27,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
        action := ctx.FormString("action")
 
        ctxUser := ctx.User
-       root := filepath.Join(models.UserPath(ctxUser.LowerName))
+       root := models.UserPath(ctxUser.LowerName)
 
        // check not a repo
        has, err := models.IsRepositoryExist(ctxUser, dir)
index 4a0900615099aea1608321c0b4eeb618bfa4c4a0..d7aa3264c58a84c1e7ba23d176b8dd54f2eb2c4a 100644 (file)
@@ -250,7 +250,7 @@ func Repos(ctx *context.Context) {
                repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum)
                repos := map[string]*models.Repository{}
                // We're going to iterate by pagesize.
-               root := filepath.Join(models.UserPath(ctxUser.Name))
+               root := models.UserPath(ctxUser.Name)
                if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
                        if err != nil {
                                if os.IsNotExist(err) {
index f59931e1bfd3724bf1921bb00b4485b3790bfe4a..e4ed4e38bd9c5d179cb6e33bd9feff7c5b1775ed 100644 (file)
@@ -275,8 +275,8 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
                                        filepath.Join(tmpBasePath, ".git", "rebase-merge", "stopped-sha"),     // Git >= 2.26
                                }
                                for _, failingCommitPath := range failingCommitPaths {
-                                       if _, statErr := os.Stat(filepath.Join(failingCommitPath)); statErr == nil {
-                                               commitShaBytes, readErr := os.ReadFile(filepath.Join(failingCommitPath))
+                                       if _, statErr := os.Stat(failingCommitPath); statErr == nil {
+                                               commitShaBytes, readErr := os.ReadFile(failingCommitPath)
                                                if readErr != nil {
                                                        // Abandon this attempt to handle the error
                                                        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())