debian-mirror-gitlab/app/services/repositories/destroy_service.rb

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

36 lines
1.2 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# 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 }
2022-07-23 23:45:48 +05:30
# Use variables that aren't methods on Project, because they are used in a callback
current_storage = repository.shard
current_path = "#{disk_path}.git"
2020-03-13 15:44:24 +05:30
2022-07-23 23:45:48 +05:30
# Because #remove happens 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
if Gitlab::Database.read_only?
Gitlab::Git::Repository.new(current_storage, current_path, nil, nil).remove
else
container.run_after_commit do
Gitlab::Git::Repository.new(current_storage, current_path, nil, nil).remove
2020-03-13 15:44:24 +05:30
end
2022-07-23 23:45:48 +05:30
end
2020-03-13 15:44:24 +05:30
2022-07-23 23:45:48 +05:30
log_info("Repository \"#{full_path}\" was removed")
2020-03-13 15:44:24 +05:30
2022-07-23 23:45:48 +05:30
success
2022-05-07 20:08:51 +05:30
rescue Gitlab::Git::Repository::NoRepository
success
2020-03-13 15:44:24 +05:30
end
end