Commit 53a0ac47 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Skip repo removing whem remove user or group

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 47a95754
...@@ -102,12 +102,16 @@ class Namespace < ActiveRecord::Base ...@@ -102,12 +102,16 @@ class Namespace < ActiveRecord::Base
# Move namespace directory into trash. # Move namespace directory into trash.
# We will remove it later async # We will remove it later async
new_path = "#{path}+#{id}+deleted" new_path = "#{path}+#{id}+deleted"
gitlab_shell.mv_namespace(path, new_path)
if gitlab_shell.mv_namespace(path, new_path)
message = "Namespace directory \"#{path}\" moved to \"#{new_path}\""
Gitlab::AppLogger.info message
# Remove namespace directroy async with delay so # Remove namespace directroy async with delay so
# GitLab has time to remove all projects first # GitLab has time to remove all projects first
GitlabShellWorker.perform_in(5.minutes, :rm_namespace, new_path) GitlabShellWorker.perform_in(5.minutes, :rm_namespace, new_path)
end end
end
def move_dir def move_dir
if gitlab_shell.mv_namespace(path_was, path) if gitlab_shell.mv_namespace(path_was, path)
......
...@@ -4,9 +4,10 @@ class DeleteUserService ...@@ -4,9 +4,10 @@ class DeleteUserService
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user' user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
user user
else else
# TODO: Skip remove repository so Namespace#rm_dir works
user.personal_projects.each do |project| user.personal_projects.each do |project|
::Projects::DestroyService.new(project, current_user, {}).execute # Skip repository removal because we remove directory with namespace
# that contain all this repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
end end
user.destroy user.destroy
......
...@@ -6,9 +6,10 @@ class DestroyGroupService ...@@ -6,9 +6,10 @@ class DestroyGroupService
end end
def execute def execute
# TODO: Skip remove repository so Namespace#rm_dir works
@group.projects.each do |project| @group.projects.each do |project|
::Projects::DestroyService.new(project, current_user, {}).execute # Skip repository removal because we remove directory with namespace
# that contain all this repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
end end
@group.destroy @group.destroy
......
...@@ -36,9 +36,11 @@ module Projects ...@@ -36,9 +36,11 @@ module Projects
private private
def remove_repository(path) def remove_repository(path)
unless gitlab_shell.exists?(path + '.git') # Skip repository removal. We use this flag when remove user or group
return true return true if params[:skip_repo] == true
end
# There is a possibility project does not have repository or wiki
return true unless gitlab_shell.exists?(path + '.git')
new_path = removal_path(path) new_path = removal_path(path)
......
require 'spec_helper'
describe DestroyGroupService do
let!(:user) { create(:user) }
let!(:group) { create(:group) }
let!(:project) { create(:project, namespace: group) }
let!(:gitlab_shell) { Gitlab::Shell.new }
let!(:remove_path) { group.path + "+#{group.id}+deleted" }
context 'database records' do
before do
destroy_group(group, user)
end
it { Group.all.should_not include(group) }
it { Project.all.should_not include(project) }
end
context 'file system' do
context 'Sidekiq inline' do
before do
# Run sidekiq immediatly to check that renamed dir will be removed
Sidekiq::Testing.inline! { destroy_group(group, user) }
end
it { gitlab_shell.exists?(group.path).should be_falsey }
it { gitlab_shell.exists?(remove_path).should be_falsey }
end
context 'Sidekiq fake' do
before do
# Dont run sidekiq to check if renamed repository exists
Sidekiq::Testing.fake! { destroy_group(group, user) }
end
it { gitlab_shell.exists?(group.path).should be_falsey }
it { gitlab_shell.exists?(remove_path).should be_truthy }
end
end
def destroy_group(group, user)
DestroyGroupService.new(group, user).execute
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