summaryrefslogtreecommitdiff
path: root/app/models/namespace.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-02-15 23:50:05 -0800
committerStan Hu <stanhu@gmail.com>2017-02-15 23:56:40 -0800
commit6606a45030ecd4035b095d33d32f1372c3562b02 (patch)
treee6d27e8d3e9d55e1e21d46d74934bc987041533c /app/models/namespace.rb
parente90ec73f651ca6153a72437d4dd01f60c38839da (diff)
downloadgitlab-ce-6606a45030ecd4035b095d33d32f1372c3562b02.tar.gz
Fix a number of race conditions that can occur during namespace deletionsh-namespace-cleanup-deleted-projects
There are two problems in the current implementation: 1. If a project is marked for deletion via the `pending_delete` flag and then the namespace was quickly deleted, it's possible that the namespace skips over that project and leaves that project in an orphaned state. 2. Before namespace deletion, the namespace attempts to clean up all the relevant storage paths. However, if all projects have been removed synchronously, then the namespace will not be able to clean anything. To prevent this, we should load the paths to be deleted before actually destroying projects. The specs were missing this second case due to a permission issue that caused project removal never to happen.
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r--app/models/namespace.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 6de4d08fc28..bd0336c984a 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -42,7 +42,7 @@ class Namespace < ActiveRecord::Base
after_commit :refresh_access_of_projects_invited_groups, on: :update, if: -> { previous_changes.key?('share_with_group_lock') }
# Save the storage paths before the projects are destroyed to use them on after destroy
- before_destroy(prepend: true) { @old_repository_storage_paths = repository_storage_paths }
+ before_destroy(prepend: true) { prepare_for_destroy }
after_destroy :rm_dir
scope :root, -> { where('type IS NULL') }
@@ -211,6 +211,14 @@ class Namespace < ActiveRecord::Base
parent_id_changed?
end
+ def prepare_for_destroy
+ old_repository_storage_paths
+ end
+
+ def old_repository_storage_paths
+ @old_repository_storage_paths ||= repository_storage_paths
+ end
+
private
def repository_storage_paths
@@ -224,7 +232,7 @@ class Namespace < ActiveRecord::Base
def rm_dir
# Remove the namespace directory in all storages paths used by member projects
- @old_repository_storage_paths.each do |repository_storage_path|
+ old_repository_storage_paths.each do |repository_storage_path|
# Move namespace directory into trash.
# We will remove it later async
new_path = "#{path}+#{id}+deleted"