mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user