Skip to content

Commit

Permalink
use IsObjectExist instead
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Dec 3, 2022
1 parent 4130d88 commit 2d36bf7
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions services/repository/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package repository

import (
"context"
"errors"
"fmt"

"code.gitea.io/gitea/models/db"
Expand Down Expand Up @@ -58,28 +57,16 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
return err
}
defer gitRepo.Close()
checkWr, checkRd, cancel := gitRepo.CatFileBatchCheck(ctx)
defer cancel()

store := lfs.NewContentStore()

return git_model.IterateLFSMetaObjectsForRepo(ctx, repo.ID, func(ctx context.Context, metaObject *git_model.LFSMetaObject, count int64) error {
total++
pointerSha := git.ComputeBlobHash([]byte(metaObject.Pointer.StringContent()))
_, err := checkWr.Write([]byte(pointerSha.String()))
if err != nil {
return fmt.Errorf("unable to write pointerSHA to cat-file in %s: %w", repo.FullName(), err)
}

_, _, _, err = git.ReadBatchLine(checkRd)
if err == nil {
if gitRepo.IsObjectExist(pointerSha.String()) {
return nil
}

if !errors.Is(err, git.ErrNotExist{}) {
return fmt.Errorf("unable to read pointerSHA from cat-file in %s: %w", repo.FullName(), err)
}

orphaned++

if !autofix {
Expand Down

0 comments on commit 2d36bf7

Please sign in to comment.