You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lfs.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package doctor
  4. import (
  5. "context"
  6. "fmt"
  7. "time"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/setting"
  10. "code.gitea.io/gitea/services/repository"
  11. )
  12. func init() {
  13. Register(&Check{
  14. Title: "Garbage collect LFS",
  15. Name: "gc-lfs",
  16. IsDefault: false,
  17. Run: garbageCollectLFSCheck,
  18. AbortIfFailed: false,
  19. SkipDatabaseInitialization: false,
  20. Priority: 1,
  21. })
  22. }
  23. func garbageCollectLFSCheck(ctx context.Context, logger log.Logger, autofix bool) error {
  24. if !setting.LFS.StartServer {
  25. return fmt.Errorf("LFS support is disabled")
  26. }
  27. if err := repository.GarbageCollectLFSMetaObjects(ctx, repository.GarbageCollectLFSMetaObjectsOptions{
  28. Logger: logger,
  29. AutoFix: autofix,
  30. // Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
  31. // and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
  32. // an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
  33. // changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
  34. // objects.
  35. //
  36. // It is likely that a week is potentially excessive but it should definitely be enough that any
  37. // unassociated LFS object is genuinely unassociated.
  38. OlderThan: time.Now().Add(-24 * time.Hour * 7),
  39. // We don't set the UpdatedLessRecentlyThan because we want to do a full GC
  40. }); err != nil {
  41. return err
  42. }
  43. return checkStorage(&checkStorageOptions{LFS: true})(ctx, logger, autofix)
  44. }