debian-mirror-gitlab/lib/gitlab/repository_size_checker.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.3 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Gitlab
# Centralized class for repository size related calculations.
class RepositorySizeChecker
attr_reader :limit
# @param current_size_proc [Proc] returns repository size in bytes
2021-01-03 14:25:43 +05:30
def initialize(current_size_proc:, limit:, namespace:, enabled: true)
2020-04-22 19:07:51 +05:30
@current_size_proc = current_size_proc
@limit = limit
2021-01-03 14:25:43 +05:30
@namespace = namespace
2020-04-22 19:07:51 +05:30
@enabled = enabled && limit != 0
end
# @return [Integer] bytes
def current_size
@current_size ||= @current_size_proc.call
end
def enabled?
@enabled
end
def above_size_limit?
return false unless enabled?
current_size > limit
end
# @param change_size [int] in bytes
def changes_will_exceed_size_limit?(change_size)
return false unless enabled?
2021-01-29 00:20:46 +05:30
above_size_limit? || exceeded_size(change_size) > 0
2020-04-22 19:07:51 +05:30
end
# @param change_size [int] in bytes
def exceeded_size(change_size = 0)
2021-01-29 00:20:46 +05:30
size = current_size + change_size - limit
[size, 0].max
2020-04-22 19:07:51 +05:30
end
def error_message
2021-01-03 14:25:43 +05:30
@error_message_object ||= ::Gitlab::RepositorySizeErrorMessage.new(self)
2020-04-22 19:07:51 +05:30
end
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
def additional_repo_storage_available?
false
end
2021-01-03 14:25:43 +05:30
private
attr_reader :namespace
2020-04-22 19:07:51 +05:30
end
end
2021-01-03 14:25:43 +05:30
2021-06-08 01:23:25 +05:30
Gitlab::RepositorySizeChecker.prepend_mod_with('Gitlab::RepositorySizeChecker')