Module: CanMoveRepositoryStorage

Extended by:
ActiveSupport::Concern
Included in:
Project, Snippet
Defined in:
app/models/concerns/can_move_repository_storage.rb

Constant Summary collapse

RepositoryReadOnlyError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#git_transfer_in_progress?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'app/models/concerns/can_move_repository_storage.rb', line 39

def git_transfer_in_progress?
  reference_counter(type: repository.repo_type).value > 0
end

#reference_counter(type:) ⇒ Object


43
44
45
# File 'app/models/concerns/can_move_repository_storage.rb', line 43

def reference_counter(type:)
  Gitlab::ReferenceCounter.new(type.identifier_for_container(self))
end

#set_repository_read_only!(skip_git_transfer_check: false) ⇒ Object

Tries to set repository as read_only, checking for existing Git transfers in progress beforehand. Setting a repository read-only will fail if it is already in that state.

Returns:

  • nil. Failures will raise an exception


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/concerns/can_move_repository_storage.rb', line 13

def set_repository_read_only!(skip_git_transfer_check: false)
  with_lock do
    raise RepositoryReadOnlyError, _('Git transfer in progress') if
      !skip_git_transfer_check && git_transfer_in_progress?

    raise RepositoryReadOnlyError, _('Repository already read-only') if
      _safe_read_repository_read_only_column

    raise ActiveRecord::RecordNotSaved, _('Database update failed') unless
      _update_repository_read_only_column(true)

    nil
  end
end

#set_repository_writable!Object

Set repository as writable again. Unlike setting it read-only, this will succeed if the repository is already writable.


30
31
32
33
34
35
36
37
# File 'app/models/concerns/can_move_repository_storage.rb', line 30

def set_repository_writable!
  with_lock do
    raise ActiveRecord::RecordNotSaved, _('Database update failed') unless
      _update_repository_read_only_column(false)

    nil
  end
end