summaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-01-01 17:05:31 +0800
committerGitHub <noreply@github.com>2022-01-01 17:05:31 +0800
commit385dc6a9927bd4bb66cb2a62e3f7e5643b973ee9 (patch)
tree287d120cd7125e59b8fa2cd6fd82a399f3189901 /routers/web/repo
parent25a290e320de630eaf8ef4e56bb435c1ecfe1032 (diff)
downloadgitea-385dc6a9927bd4bb66cb2a62e3f7e5643b973ee9.tar.gz
gitea-385dc6a9927bd4bb66cb2a62e3f7e5643b973ee9.zip
Allow admin to associate missing LFS objects for repositories (#18143)
This PR reworked the Find pointer files feature in Settings -> LFS page. When a LFS object is missing from database but exists in LFS content store, admin can associate it to the repository by clicking the Associate button. This PR is not perfect (because the LFS module itself should be improved too), it's just a nice-to-have feature to help users recover their LFS repositories (eg: database was lost / table was truncated)
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/lfs.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go
index 28d6b12860..6cc05430dd 100644
--- a/routers/web/repo/lfs.go
+++ b/routers/web/repo/lfs.go
@@ -421,12 +421,13 @@ func LFSPointerFiles(ctx *context.Context) {
var numAssociated, numNoExist, numAssociatable int
type pointerResult struct {
- SHA string
- Oid string
- Size int64
- InRepo bool
- Exists bool
- Accessible bool
+ SHA string
+ Oid string
+ Size int64
+ InRepo bool
+ Exists bool
+ Accessible bool
+ Associatable bool
}
results := []pointerResult{}
@@ -461,22 +462,29 @@ func LFSPointerFiles(ctx *context.Context) {
// Can we fix?
// OK well that's "simple"
// - we need to check whether current user has access to a repo that has access to the file
- result.Accessible, err = models.LFSObjectAccessible(ctx.User, pointerBlob.Oid)
+ result.Associatable, err = models.LFSObjectAccessible(ctx.User, pointerBlob.Oid)
if err != nil {
return err
}
- } else {
- result.Accessible = true
+ if !result.Associatable {
+ associated, err := models.LFSObjectIsAssociated(pointerBlob.Oid)
+ if err != nil {
+ return err
+ }
+ result.Associatable = !associated
+ }
}
}
+ result.Accessible = result.InRepo || result.Associatable
+
if result.InRepo {
numAssociated++
}
if !result.Exists {
numNoExist++
}
- if !result.InRepo && result.Accessible {
+ if result.Associatable {
numAssociatable++
}