mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 22:39:36 +00:00
refactor: hide git repo path details from more packages (#38601)
Remove `RepoPath` from "models/repo" package, remove `UserPath` from "models/user" package, use `WithRepo` for more places, fine tune tests.
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
package gitrepo
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"gitea.dev/modules/setting"
|
||||
@@ -39,6 +42,13 @@ func RepoLocalPath(repo RepositoryFacade) string {
|
||||
return setting.RepoRootPath + string(filepath.Separator) + filepath.FromSlash(repoLoc)
|
||||
}
|
||||
|
||||
func UserLocalPath(userName string) string {
|
||||
if setting.RepoRootPath == "" {
|
||||
panic("repo root path is not initialized")
|
||||
}
|
||||
return filepath.Join(setting.RepoRootPath, filepath.Clean(strings.ToLower(userName)))
|
||||
}
|
||||
|
||||
func repoLogNameByLocation(loc string) string {
|
||||
t := filepath.FromSlash(loc)
|
||||
// hide the parent paths, then the name should be safe for end users
|
||||
@@ -100,3 +110,7 @@ func (r *repositoryManaged) GitRepoLocation() string {
|
||||
func RepositoryManaged(id, loc string) RepositoryFacade {
|
||||
return &repositoryManaged{id: id, loc: filepath.Clean(loc)}
|
||||
}
|
||||
|
||||
func RepoLocalFS(repo RepositoryFacade) fs.FS {
|
||||
return os.DirFS(RepoLocalPath(repo))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user