Commit 815f35be authored by Stan Hu's avatar Stan Hu

Merge branch '40352-ignore-hashed-repos-cleanup-dirs' into 'master'

ignore hashed repositories when doing rake gitlab:cleanup:dirs

Closes #40352

See merge request gitlab-org/gitlab-ce!15600
parents d199ecd4 30a9fc33
---
title: Ensure that rake gitlab:cleanup:repos task does not mess with hashed repositories
merge_request: 15520
author:
type: fixed
---
title: Ensure that rake gitlab:cleanup:dirs task does not mess with hashed repositories
merge_request: 15600
author:
type: fixed
namespace :gitlab do namespace :gitlab do
namespace :cleanup do namespace :cleanup do
HASHED_REPOSITORY_NAME = '@hashed'.freeze
desc "GitLab | Cleanup | Clean namespaces" desc "GitLab | Cleanup | Clean namespaces"
task dirs: :environment do task dirs: :environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
remove_flag = ENV['REMOVE'] remove_flag = ENV['REMOVE']
namespaces = Namespace.pluck(:path) namespaces = Namespace.pluck(:path)
namespaces << HASHED_REPOSITORY_NAME # add so that it will be ignored
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
git_base_path = repository_storage['path'] git_base_path = repository_storage['path']
all_dirs = Dir.glob(git_base_path + '/*') all_dirs = Dir.glob(git_base_path + '/*')
...@@ -62,7 +65,7 @@ namespace :gitlab do ...@@ -62,7 +65,7 @@ namespace :gitlab do
# TODO ignoring hashed repositories for now. But revisit to fully support # TODO ignoring hashed repositories for now. But revisit to fully support
# possible orphaned hashed repos # possible orphaned hashed repos
next if repo_with_namespace.start_with?('@hashed/') || Project.find_by_full_path(repo_with_namespace) next if repo_with_namespace.start_with?("#{HASHED_REPOSITORY_NAME}/") || Project.find_by_full_path(repo_with_namespace)
new_path = path + move_suffix new_path = path + move_suffix
puts path.inspect + ' -> ' + new_path.inspect puts path.inspect + ' -> ' + new_path.inspect
......
...@@ -5,7 +5,7 @@ describe 'gitlab:cleanup rake tasks' do ...@@ -5,7 +5,7 @@ describe 'gitlab:cleanup rake tasks' do
Rake.application.rake_require 'tasks/gitlab/cleanup' Rake.application.rake_require 'tasks/gitlab/cleanup'
end end
context 'cleanup repositories' do describe 'cleanup' do
let(:gitaly_address) { Gitlab.config.repositories.storages.default.gitaly_address } let(:gitaly_address) { Gitlab.config.repositories.storages.default.gitaly_address }
let(:storages) do let(:storages) do
{ {
...@@ -22,8 +22,13 @@ describe 'gitlab:cleanup rake tasks' do ...@@ -22,8 +22,13 @@ describe 'gitlab:cleanup rake tasks' do
FileUtils.rm_rf(Settings.absolute('tmp/tests/default_storage')) FileUtils.rm_rf(Settings.absolute('tmp/tests/default_storage'))
end end
it 'moves it to an orphaned path' do describe 'cleanup:repos' do
before do
FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/broken/project.git')) FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/broken/project.git'))
FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))
end
it 'moves it to an orphaned path' do
run_rake_task('gitlab:cleanup:repos') run_rake_task('gitlab:cleanup:repos')
repo_list = Dir['tmp/tests/default_storage/broken/*'] repo_list = Dir['tmp/tests/default_storage/broken/*']
...@@ -31,11 +36,32 @@ describe 'gitlab:cleanup rake tasks' do ...@@ -31,11 +36,32 @@ describe 'gitlab:cleanup rake tasks' do
end end
it 'ignores @hashed repos' do it 'ignores @hashed repos' do
run_rake_task('gitlab:cleanup:repos')
expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))).to be_truthy
end
end
describe 'cleanup:dirs' do
it 'removes missing namespaces' do
FileUtils.mkdir_p(Settings.absolute("tmp/tests/default_storage/namespace_1/project.git"))
FileUtils.mkdir_p(Settings.absolute("tmp/tests/default_storage/namespace_2/project.git"))
allow(Namespace).to receive(:pluck).and_return('namespace_1')
stub_env('REMOVE', 'true')
run_rake_task('gitlab:cleanup:dirs')
expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/namespace_1'))).to be_truthy
expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/namespace_2'))).to be_falsey
end
it 'ignores @hashed directory' do
FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git')) FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))
run_rake_task('gitlab:cleanup:repos') run_rake_task('gitlab:cleanup:dirs')
expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))).to be_truthy expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))).to be_truthy
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment