2020-01-27 22:08:39 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Repositories::DestroyService < Repositories::BaseService
|
|
|
|
def execute
|
|
|
|
return success unless repository
|
|
|
|
return success unless repo_exists?(disk_path)
|
|
|
|
|
|
|
|
# Flush the cache for both repositories. This has to be done _before_
|
|
|
|
# removing the physical repositories as some expiration code depends on
|
|
|
|
# Git data (e.g. a list of branch names).
|
|
|
|
ignore_git_errors { repository.before_delete }
|
|
|
|
|
|
|
|
if mv_repository(disk_path, removal_path)
|
|
|
|
log_info(%Q{Repository "#{disk_path}" moved to "#{removal_path}" for repository "#{full_path}"})
|
|
|
|
|
|
|
|
current_repository = repository
|
2020-06-29 11:08:56 -04:00
|
|
|
|
|
|
|
# Because GitlabShellWorker is inside a run_after_commit callback it will
|
|
|
|
# never be triggered on a read-only instance.
|
|
|
|
#
|
|
|
|
# Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/223272
|
2021-08-02 05:10:09 -04:00
|
|
|
if Gitlab::Database.read_only?
|
2020-01-27 22:08:39 -05:00
|
|
|
Repositories::ShellDestroyService.new(current_repository).execute
|
2020-06-29 11:08:56 -04:00
|
|
|
else
|
|
|
|
container.run_after_commit do
|
|
|
|
Repositories::ShellDestroyService.new(current_repository).execute
|
|
|
|
end
|
2020-01-27 22:08:39 -05:00
|
|
|
end
|
|
|
|
|
2020-02-27 19:09:08 -05:00
|
|
|
log_info("Repository \"#{full_path}\" was removed")
|
2020-01-27 22:08:39 -05:00
|
|
|
|
|
|
|
success
|
2022-03-09 10:08:40 -05:00
|
|
|
elsif repo_exists?(disk_path)
|
2020-01-27 22:08:39 -05:00
|
|
|
move_error(disk_path)
|
2022-03-09 10:08:40 -05:00
|
|
|
else
|
|
|
|
success
|
2020-01-27 22:08:39 -05:00
|
|
|
end
|
2022-03-09 10:08:40 -05:00
|
|
|
rescue Gitlab::Git::Repository::NoRepository
|
|
|
|
success
|
2020-01-27 22:08:39 -05:00
|
|
|
end
|
|
|
|
end
|