mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Use filepath.Join instead of path.Join for file system file operations (#33978)
This commit is contained in:
@@ -7,11 +7,9 @@ package git
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
@@ -51,7 +49,7 @@ func GetHook(repoPath, name string) (*Hook, error) {
|
||||
}
|
||||
h := &Hook{
|
||||
name: name,
|
||||
path: path.Join(repoPath, "hooks", name+".d", name),
|
||||
path: filepath.Join(repoPath, "hooks", name+".d", name),
|
||||
}
|
||||
samplePath := filepath.Join(repoPath, "hooks", name+".sample")
|
||||
if isFile(h.path) {
|
||||
@@ -103,7 +101,7 @@ func (h *Hook) Update() error {
|
||||
|
||||
// ListHooks returns a list of Git hooks of given repository.
|
||||
func ListHooks(repoPath string) (_ []*Hook, err error) {
|
||||
if !isDir(path.Join(repoPath, "hooks")) {
|
||||
if !isDir(filepath.Join(repoPath, "hooks")) {
|
||||
return nil, errors.New("hooks path does not exist")
|
||||
}
|
||||
|
||||
@@ -116,28 +114,3 @@ func ListHooks(repoPath string) (_ []*Hook, err error) {
|
||||
}
|
||||
return hooks, nil
|
||||
}
|
||||
|
||||
const (
|
||||
// HookPathUpdate hook update path
|
||||
HookPathUpdate = "hooks/update"
|
||||
)
|
||||
|
||||
// SetUpdateHook writes given content to update hook of the repository.
|
||||
func SetUpdateHook(repoPath, content string) (err error) {
|
||||
log.Debug("Setting update hook: %s", repoPath)
|
||||
hookPath := path.Join(repoPath, HookPathUpdate)
|
||||
isExist, err := util.IsExist(hookPath)
|
||||
if err != nil {
|
||||
log.Debug("Unable to check if %s exists. Error: %v", hookPath, err)
|
||||
return err
|
||||
}
|
||||
if isExist {
|
||||
err = util.Remove(hookPath)
|
||||
} else {
|
||||
err = os.MkdirAll(path.Dir(hookPath), os.ModePerm)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(hookPath, []byte(content), 0o777)
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ package git
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
gitealog "code.gitea.io/gitea/modules/log"
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
// CommitNodeIndex returns the index for walking commit graph
|
||||
func (r *Repository) CommitNodeIndex() (cgobject.CommitNodeIndex, *os.File) {
|
||||
indexPath := path.Join(r.Path, "objects", "info", "commit-graph")
|
||||
indexPath := filepath.Join(r.Path, "objects", "info", "commit-graph")
|
||||
|
||||
file, err := os.Open(indexPath)
|
||||
if err == nil {
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -72,7 +71,7 @@ func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error
|
||||
}
|
||||
|
||||
// Create/Remove git-daemon-export-ok for git-daemon...
|
||||
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
|
||||
daemonExportFile := filepath.Join(repo.RepoPath(), `git-daemon-export-ok`)
|
||||
|
||||
isExist, err := util.IsExist(daemonExportFile)
|
||||
if err != nil {
|
||||
|
@@ -6,7 +6,6 @@ package repository
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@@ -19,7 +18,7 @@ func LocalCopyPath() string {
|
||||
if filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
|
||||
return setting.Repository.Local.LocalCopyPath
|
||||
}
|
||||
return path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath)
|
||||
return filepath.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath)
|
||||
}
|
||||
|
||||
// CreateTemporaryPath creates a temporary path
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
golog "log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -41,7 +40,7 @@ func loadLogGlobalFrom(rootCfg ConfigProvider) {
|
||||
Log.BufferLen = sec.Key("BUFFER_LEN").MustInt(10000)
|
||||
Log.Mode = sec.Key("MODE").MustString("console")
|
||||
|
||||
Log.RootPath = sec.Key("ROOT_PATH").MustString(path.Join(AppWorkPath, "log"))
|
||||
Log.RootPath = sec.Key("ROOT_PATH").MustString(filepath.Join(AppWorkPath, "log"))
|
||||
if !filepath.IsAbs(Log.RootPath) {
|
||||
Log.RootPath = filepath.Join(AppWorkPath, Log.RootPath)
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ package setting
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -284,7 +283,7 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
|
||||
Repository.GoGetCloneURLProtocol = sec.Key("GO_GET_CLONE_URL_PROTOCOL").MustString("https")
|
||||
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
|
||||
Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString(Repository.DefaultBranch)
|
||||
RepoRootPath = sec.Key("ROOT").MustString(path.Join(AppDataPath, "gitea-repositories"))
|
||||
RepoRootPath = sec.Key("ROOT").MustString(filepath.Join(AppDataPath, "gitea-repositories"))
|
||||
if !filepath.IsAbs(RepoRootPath) {
|
||||
RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)
|
||||
} else {
|
||||
@@ -363,7 +362,7 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(Repository.Upload.TempPath) {
|
||||
Repository.Upload.TempPath = path.Join(AppWorkPath, Repository.Upload.TempPath)
|
||||
Repository.Upload.TempPath = filepath.Join(AppWorkPath, Repository.Upload.TempPath)
|
||||
}
|
||||
|
||||
if err := loadRepoArchiveFrom(rootCfg); err != nil {
|
||||
|
@@ -5,7 +5,6 @@ package setting
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -111,7 +110,7 @@ func loadSSHFrom(rootCfg ConfigProvider) {
|
||||
}
|
||||
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
|
||||
|
||||
SSH.RootPath = path.Join(homeDir, ".ssh")
|
||||
SSH.RootPath = filepath.Join(homeDir, ".ssh")
|
||||
serverCiphers := sec.Key("SSH_SERVER_CIPHERS").Strings(",")
|
||||
if len(serverCiphers) > 0 {
|
||||
SSH.ServerCiphers = serverCiphers
|
||||
|
Reference in New Issue
Block a user