Skip to content

Commit

Permalink
Associate LFS pointer on download
Browse files Browse the repository at this point in the history
Temporary measure to work around
go-gitea#17715
  • Loading branch information
parnic-sks committed Sep 6, 2022
1 parent 32eef4a commit 2c16b47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion models/git/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func CountLFSMetaObjects(repoID int64) (int64, error) {

// LFSObjectAccessible checks if a provided Oid is accessible to the user
func LFSObjectAccessible(user *user_model.User, oid string) (bool, error) {
if user.IsAdmin {
if user != nil && user.IsAdmin {
count, err := db.GetEngine(db.DefaultContext).Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
return count > 0, err
}
Expand Down
20 changes: 20 additions & 0 deletions services/lfs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,26 @@ func BatchHandler(ctx *context.Context) {
responseObject = buildObjectResponse(rc, p, false, !exists, err)
} else {
var err *lfs_module.ObjectError

if exists && meta == nil {
accessible, accessibleErr := git_model.LFSObjectAccessible(ctx.Doer, p.Oid)
if accessibleErr != nil {
log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err)
writeStatus(ctx, http.StatusInternalServerError)
return
}
if accessible {
_, newMetaObjErr := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
if newMetaObjErr != nil {
log.Error("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
writeStatus(ctx, http.StatusInternalServerError)
return
}
} else {
exists = false
}
}

if !exists || meta == nil {
err = &lfs_module.ObjectError{
Code: http.StatusNotFound,
Expand Down

0 comments on commit 2c16b47

Please sign in to comment.