diff options
author | digitalMoksha <bwalker@gitlab.com> | 2017-11-24 21:29:25 +0300 |
---|---|---|
committer | digitalMoksha <bwalker@gitlab.com> | 2017-11-24 21:29:25 +0300 |
commit | 17069a9547c14c53491af76035c06dc66b8d8049 (patch) | |
tree | 394aebb6cee6a1f5c6a792f9fea199778b1667aa | |
parent | b355ebc4c9b38320366d7640ecf51da23fbb7ea1 (diff) |
ignore hashed repositories when doing rake gitlab:cleanup:dirs
-rw-r--r-- | lib/tasks/gitlab/cleanup.rake | 3 | ||||
-rw-r--r-- | spec/tasks/gitlab/cleanup_rake_spec.rb | 47 |
2 files changed, 39 insertions, 11 deletions
diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake index 301affc9522..111576ea802 100644 --- a/lib/tasks/gitlab/cleanup.rake +++ b/lib/tasks/gitlab/cleanup.rake @@ -5,7 +5,8 @@ namespace :gitlab do warn_user_is_not_gitlab remove_flag = ENV['REMOVE'] - namespaces = Namespace.pluck(:path) + namespaces = Namespace.pluck(:path) + namespaces << '@hashed' # add so that it will be ignored Gitlab.config.repositories.storages.each do |name, repository_storage| git_base_path = repository_storage['path'] all_dirs = Dir.glob(git_base_path + '/*') diff --git a/spec/tasks/gitlab/cleanup_rake_spec.rb b/spec/tasks/gitlab/cleanup_rake_spec.rb index 641eccfd334..647f40fa695 100644 --- a/spec/tasks/gitlab/cleanup_rake_spec.rb +++ b/spec/tasks/gitlab/cleanup_rake_spec.rb @@ -5,7 +5,8 @@ describe 'gitlab:cleanup rake tasks' do Rake.application.rake_require 'tasks/gitlab/cleanup' end - context 'cleanup repositories' do + describe 'cleanup' do + let(:gitaly_address) { Gitlab.config.repositories.storages.default.gitaly_address } let(:storages) do { @@ -22,20 +23,46 @@ describe 'gitlab:cleanup rake tasks' do FileUtils.rm_rf(Settings.absolute('tmp/tests/default_storage')) end - it 'moves it to an orphaned path' do - FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/broken/project.git')) - run_rake_task('gitlab:cleanup:repos') - repo_list = Dir['tmp/tests/default_storage/broken/*'] + 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/@hashed/12/34/5678.git')) + end + + it 'moves it to an orphaned path' do + run_rake_task('gitlab:cleanup:repos') + repo_list = Dir['tmp/tests/default_storage/broken/*'] + + expect(repo_list.first).to include('+orphaned+') + end + + it 'ignores @hashed repos' do + run_rake_task('gitlab:cleanup:repos') - expect(repo_list.first).to include('+orphaned+') + expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))).to be_truthy + end end - it 'ignores @hashed repos' do - FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git')) + 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')) - 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 |