Class: Repositories::BaseService

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

Constant Summary collapse

DELETED_FLAG =
'+deleted'

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.


12
13
14
# File 'app/services/repositories/base_service.rb', line 12

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository


8
9
10
# File 'app/services/repositories/base_service.rb', line 8

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.


39
40
41
42
43
# File 'app/services/repositories/base_service.rb', line 39

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


45
46
47
48
49
50
# File 'app/services/repositories/base_service.rb', line 45

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


20
21
22
23
24
# File 'app/services/repositories/base_service.rb', line 20

def mv_repository(from_path, to_path)
  return true unless repo_exists?(from_path)

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

#removal_pathObject

Build a path for removing repositories We use `+` because its not allowed by GitLab so user can not create project with name cookies+119+deleted and capture someone stalled repository

gitlab/cookies.git -> gitlab/cookies+119+deleted.git


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

def removal_path
  "#{disk_path}+#{container.id}#{DELETED_FLAG}"
end

#repo_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)

16
17
18
# File 'app/services/repositories/base_service.rb', line 16

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