summaryrefslogtreecommitdiff
path: root/lib/gitlab/checks/lfs_check.rb
blob: 1d1d24c8fccf146ca5ab7079ce1a9b4dc4327e7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module Gitlab
  module Checks
    class LfsCheck < BaseBulkChecker
      LOG_MESSAGE = 'Scanning repository for blobs stored in LFS and verifying their files have been uploaded to GitLab...'
      ERROR_MESSAGE = 'LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".'

      def validate!
        # This feature flag is used for disabling integrity check on some envs
        # because these costy calculations may cause performance issues
        return unless Feature.enabled?(:lfs_check, project)

        return unless project.lfs_enabled?

        logger.log_timed(LOG_MESSAGE) do
          newrevs = changes.map { |change| change[:newrev] }
          lfs_check = Checks::LfsIntegrity.new(project, newrevs, logger.time_left)

          if lfs_check.objects_missing?
            raise GitAccess::ForbiddenError, ERROR_MESSAGE
          end
        end
      end
    end
  end
end