Class: Repositories::BaseService

Inherits:
BaseService show all
Includes:
Gitlab::ShellAdapter
Defined in:
app/services/repositories/base_service.rb

Direct Known Subclasses

DestroyService, HousekeepingService

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::ShellAdapter

#gitlab_shell

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(repository) ⇒ BaseService

Returns a new instance of BaseService.


10
11
12
# File 'app/services/repositories/base_service.rb', line 10

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.


6
7
8
# File 'app/services/repositories/base_service.rb', line 6

def repository
  @repository
end

Instance Method Details

#ignore_git_errors(&block) ⇒ Object

If we get a Gitaly error, the repository may be corrupted. We can ignore these errors since we're going to trash the repositories anyway.


25
26
27
28
29
# File 'app/services/repositories/base_service.rb', line 25

def ignore_git_errors(&block)
  yield
rescue Gitlab::Git::CommandError => e
  Gitlab::GitLogger.warn(class: self.class.name, container_id: container.id, disk_path: disk_path, message: e.to_s)
end

#move_error(path) ⇒ Object


31
32
33
34
35
36
# File 'app/services/repositories/base_service.rb', line 31

def move_error(path)
  error = %Q{Repository "#{path}" could not be moved}

  log_error(error)
  error(error)
end

#mv_repository(from_path, to_path) ⇒ Object


18
19
20
# File 'app/services/repositories/base_service.rb', line 18

def mv_repository(from_path, to_path)
  gitlab_shell.mv_repository(repository.shard, from_path, to_path)
end

#repo_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
# File 'app/services/repositories/base_service.rb', line 14

def repo_exists?(path)
  gitlab_shell.repository_exists?(repository.shard, path + '.git')
end