mirror of
https://codeberg.org/forgejo-aneksajo/forgejo-aneksajo.git
synced 2025-07-27 17:00:05 +02:00
Compare commits
2 commits
7bbc84ed5e
...
977627fe6e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
977627fe6e | ||
![]() |
85fb7bafd7 |
3 changed files with 23 additions and 17 deletions
|
@ -152,10 +152,7 @@ func IsAnnexRepo(repo *git.Repository) bool {
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var uuid2repoPathCache = make(map[string]string)
|
||||||
uuid2repoPathCache = make(map[string]string)
|
|
||||||
repoPath2uuidCache = make(map[string]string)
|
|
||||||
)
|
|
||||||
|
|
||||||
func Init() error {
|
func Init() error {
|
||||||
if !setting.Annex.Enabled {
|
if !setting.Annex.Enabled {
|
||||||
|
@ -179,10 +176,6 @@ func updateUUID2RepoPathCache() error {
|
||||||
}
|
}
|
||||||
for _, configFile := range configFiles {
|
for _, configFile := range configFiles {
|
||||||
repoPath := strings.TrimSuffix(configFile, "/config")
|
repoPath := strings.TrimSuffix(configFile, "/config")
|
||||||
_, ok := repoPath2uuidCache[repoPath]
|
|
||||||
if ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
config, err := ini.Load(configFile)
|
config, err := ini.Load(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -190,7 +183,6 @@ func updateUUID2RepoPathCache() error {
|
||||||
repoUUID := config.Section("annex").Key("uuid").Value()
|
repoUUID := config.Section("annex").Key("uuid").Value()
|
||||||
if repoUUID != "" {
|
if repoUUID != "" {
|
||||||
uuid2repoPathCache[repoUUID] = repoPath
|
uuid2repoPathCache[repoUUID] = repoPath
|
||||||
repoPath2uuidCache[repoPath] = repoUUID
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -219,11 +211,6 @@ func checkValidity(uuid, repoPath string) (bool, error) {
|
||||||
return uuid == repoUUID, nil
|
return uuid == repoUUID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeCachedEntries(uuid, repoPath string) {
|
|
||||||
delete(uuid2repoPathCache, uuid)
|
|
||||||
delete(repoPath2uuidCache, repoPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UUID2RepoPath(uuid string) (string, error) {
|
func UUID2RepoPath(uuid string) (string, error) {
|
||||||
// Get the current cache entry for the UUID
|
// Get the current cache entry for the UUID
|
||||||
repoPath, err := repoPathFromUUIDCache(uuid)
|
repoPath, err := repoPathFromUUIDCache(uuid)
|
||||||
|
@ -237,7 +224,7 @@ func UUID2RepoPath(uuid string) (string, error) {
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
// If it isn't, remove the cache entry and try again
|
// If it isn't, remove the cache entry and try again
|
||||||
removeCachedEntries(uuid, repoPath)
|
delete(uuid2repoPathCache, uuid)
|
||||||
return UUID2RepoPath(uuid)
|
return UUID2RepoPath(uuid)
|
||||||
}
|
}
|
||||||
// Otherwise just return the cached entry
|
// Otherwise just return the cached entry
|
||||||
|
|
|
@ -36,6 +36,7 @@ func AnnexP2PHTTP(ctx *services_context.Context) {
|
||||||
uuid := ctx.Params(":uuid")
|
uuid := ctx.Params(":uuid")
|
||||||
repoPath, err := annex.UUID2RepoPath(uuid)
|
repoPath, err := annex.UUID2RepoPath(uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("%v", err)
|
||||||
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -45,12 +46,14 @@ func AnnexP2PHTTP(ctx *services_context.Context) {
|
||||||
owner := parts[len(parts)-2]
|
owner := parts[len(parts)-2]
|
||||||
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner, repoName)
|
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("%v", err)
|
||||||
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
p, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("%v", err)
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,8 +243,9 @@ func httpBase(ctx *context.Context) *serviceHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isRequestToConfig := strings.HasSuffix(ctx.Req.URL.Path, "/config")
|
||||||
if !repoExist {
|
if !repoExist {
|
||||||
if !receivePack {
|
if !receivePack && !isRequestToConfig {
|
||||||
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
ctx.PlainText(http.StatusNotFound, "Repository not found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -264,7 +265,7 @@ func httpBase(ctx *context.Context) *serviceHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return dummy payload if GET receive-pack
|
// Return dummy payload if GET receive-pack
|
||||||
if ctx.Req.Method == http.MethodGet {
|
if ctx.Req.Method == http.MethodGet && !isRequestToConfig {
|
||||||
dummyInfoRefs(ctx)
|
dummyInfoRefs(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -551,6 +552,21 @@ func GetConfig(ctx *context.Context) {
|
||||||
h := httpBase(ctx)
|
h := httpBase(ctx)
|
||||||
if h != nil {
|
if h != nil {
|
||||||
setHeaderNoCache(ctx)
|
setHeaderNoCache(ctx)
|
||||||
|
if setting.Annex.Enabled && strings.HasPrefix(ctx.Req.UserAgent(), "git-annex/") {
|
||||||
|
p, err := access_model.GetUserRepoPermission(ctx, h.repo, ctx.Doer)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.CanAccess(perm.AccessModeWrite, unit.TypeCode) {
|
||||||
|
_, _, err := git.NewCommand(ctx, "annex", "init").RunStdString(&git.RunOpts{Dir: h.getRepoDir()})
|
||||||
|
if err != nil {
|
||||||
|
ctx.Resp.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
config, err := os.ReadFile(filepath.Join(h.getRepoDir(), "config"))
|
config, err := os.ReadFile(filepath.Join(h.getRepoDir(), "config"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to read git config file: %v", err)
|
log.Error("Failed to read git config file: %v", err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue