mirror of
https://codeberg.org/forgejo-aneksajo/forgejo-aneksajo.git
synced 2025-08-03 02:00:02 +02:00
Compare commits
No commits in common. "e118cb948595e7f81c401dfdc76192bec40fd324" and "b0a9f5650863be573835617feb52d00fe0120694" have entirely different histories.
e118cb9485
...
b0a9f56508
2 changed files with 1 additions and 47 deletions
|
@ -20,7 +20,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -101,14 +100,6 @@ var (
|
||||||
repoPath2uuidCache = make(map[string]string)
|
repoPath2uuidCache = make(map[string]string)
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() error {
|
|
||||||
if !setting.Annex.Enabled {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
log.Info("Populating the git-annex UUID cache with existing repositories")
|
|
||||||
return updateUUID2RepoPathCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateUUID2RepoPathCache() error {
|
func updateUUID2RepoPathCache() error {
|
||||||
return filepath.WalkDir(setting.RepoRootPath, func(path string, d fs.DirEntry, err error) error {
|
return filepath.WalkDir(setting.RepoRootPath, func(path string, d fs.DirEntry, err error) error {
|
||||||
if err == nil && repoConfigFileRe.MatchString(path) {
|
if err == nil && repoConfigFileRe.MatchString(path) {
|
||||||
|
@ -131,7 +122,7 @@ func updateUUID2RepoPathCache() error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func repoPathFromUUIDCache(uuid string) (string, error) {
|
func UUID2RepoPath(uuid string) (string, error) {
|
||||||
if repoPath, ok := uuid2repoPathCache[uuid]; ok {
|
if repoPath, ok := uuid2repoPathCache[uuid]; ok {
|
||||||
return repoPath, nil
|
return repoPath, nil
|
||||||
}
|
}
|
||||||
|
@ -144,37 +135,3 @@ func repoPathFromUUIDCache(uuid string) (string, error) {
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("no repository known for UUID '%s'", uuid)
|
return "", fmt.Errorf("no repository known for UUID '%s'", uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkValidity(uuid, repoPath string) (bool, error) {
|
|
||||||
stdout, _, err := git.NewCommand(git.DefaultContext, "config", "annex.uuid").RunStdString(&git.RunOpts{Dir: repoPath})
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
repoUUID := strings.TrimSpace(stdout)
|
|
||||||
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)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
// Check if it is still up-to-date
|
|
||||||
valid, err := checkValidity(uuid, repoPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if !valid {
|
|
||||||
// If it isn't, remove the cache entry and try again
|
|
||||||
removeCachedEntries(uuid, repoPath)
|
|
||||||
return UUID2RepoPath(uuid)
|
|
||||||
}
|
|
||||||
// Otherwise just return the cached entry
|
|
||||||
return repoPath, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
authmodel "code.gitea.io/gitea/models/auth"
|
authmodel "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/modules/annex"
|
|
||||||
"code.gitea.io/gitea/modules/cache"
|
"code.gitea.io/gitea/modules/cache"
|
||||||
"code.gitea.io/gitea/modules/eventsource"
|
"code.gitea.io/gitea/modules/eventsource"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
|
@ -168,8 +167,6 @@ func InitWebInstalled(ctx context.Context) {
|
||||||
|
|
||||||
actions_service.Init()
|
actions_service.Init()
|
||||||
|
|
||||||
mustInit(annex.Init)
|
|
||||||
|
|
||||||
// Finally start up the cron
|
// Finally start up the cron
|
||||||
cron.NewContext(ctx)
|
cron.NewContext(ctx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue