diff --git a/modules/annex/annex.go b/modules/annex/annex.go index e4e68b9e78..26775581ca 100644 --- a/modules/annex/annex.go +++ b/modules/annex/annex.go @@ -152,7 +152,10 @@ func IsAnnexRepo(repo *git.Repository) bool { return err == nil } -var uuid2repoPathCache = make(map[string]string) +var ( + uuid2repoPathCache = make(map[string]string) + repoPath2uuidCache = make(map[string]string) +) func Init() error { if !setting.Annex.Enabled { @@ -176,6 +179,10 @@ func updateUUID2RepoPathCache() error { } for _, configFile := range configFiles { repoPath := strings.TrimSuffix(configFile, "/config") + _, ok := repoPath2uuidCache[repoPath] + if ok { + continue + } config, err := ini.Load(configFile) if err != nil { continue @@ -183,6 +190,7 @@ func updateUUID2RepoPathCache() error { repoUUID := config.Section("annex").Key("uuid").Value() if repoUUID != "" { uuid2repoPathCache[repoUUID] = repoPath + repoPath2uuidCache[repoPath] = repoUUID } } return nil @@ -211,6 +219,11 @@ func checkValidity(uuid, repoPath string) (bool, error) { return uuid == repoUUID, nil } +func removeCachedEntries(uuid, repoPath string) { + delete(uuid2repoPathCache, uuid) + delete(repoPath2uuidCache, repoPath) +} + func UUID2RepoPath(uuid string) (string, error) { // Get the current cache entry for the UUID repoPath, err := repoPathFromUUIDCache(uuid) @@ -224,7 +237,7 @@ func UUID2RepoPath(uuid string) (string, error) { } if !valid { // If it isn't, remove the cache entry and try again - delete(uuid2repoPathCache, uuid) + removeCachedEntries(uuid, repoPath) return UUID2RepoPath(uuid) } // Otherwise just return the cached entry diff --git a/routers/web/repo/annex.go b/routers/web/repo/annex.go index e150ff70ca..fa4d1c6ba4 100644 --- a/routers/web/repo/annex.go +++ b/routers/web/repo/annex.go @@ -36,7 +36,6 @@ func AnnexP2PHTTP(ctx *services_context.Context) { uuid := ctx.Params(":uuid") repoPath, err := annex.UUID2RepoPath(uuid) if err != nil { - log.Error("%v", err) ctx.PlainText(http.StatusNotFound, "Repository not found") return } @@ -46,14 +45,12 @@ func AnnexP2PHTTP(ctx *services_context.Context) { owner := parts[len(parts)-2] repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner, repoName) if err != nil { - log.Error("%v", err) ctx.PlainText(http.StatusNotFound, "Repository not found") return } p, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - log.Error("%v", err) ctx.ServerError("GetUserRepoPermission", err) return } diff --git a/routers/web/repo/githttp.go b/routers/web/repo/githttp.go index ada9d350c9..58a14fe26c 100644 --- a/routers/web/repo/githttp.go +++ b/routers/web/repo/githttp.go @@ -243,9 +243,8 @@ func httpBase(ctx *context.Context) *serviceHandler { } } - isRequestToConfig := strings.HasSuffix(ctx.Req.URL.Path, "/config") if !repoExist { - if !receivePack && !isRequestToConfig { + if !receivePack { ctx.PlainText(http.StatusNotFound, "Repository not found") return nil } @@ -265,7 +264,7 @@ func httpBase(ctx *context.Context) *serviceHandler { } // Return dummy payload if GET receive-pack - if ctx.Req.Method == http.MethodGet && !isRequestToConfig { + if ctx.Req.Method == http.MethodGet { dummyInfoRefs(ctx) return nil } @@ -552,21 +551,6 @@ func GetConfig(ctx *context.Context) { h := httpBase(ctx) if h != nil { 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")) if err != nil { log.Error("Failed to read git config file: %v", err)