diff options
author | Nick Thomas <nick@gitlab.com> | 2018-01-23 22:03:02 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-02-05 13:38:57 +0300 |
commit | 30a43b7e04b98616f379bdd800532c3354df8b19 (patch) | |
tree | 62711e0084cf584b350469e41f5a02e5654de427 /app | |
parent | f5990e444a98dc259e2af8c373910cd9ec15b0bd (diff) |
Fix export removal for hashed-storage projects within a renamed or deleted namespace
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/storage/legacy_namespace.rb | 16 | ||||
-rw-r--r-- | app/models/group.rb | 6 | ||||
-rw-r--r-- | app/models/namespace.rb | 18 | ||||
-rw-r--r-- | app/models/project.rb | 8 |
4 files changed, 27 insertions, 21 deletions
diff --git a/app/models/concerns/storage/legacy_namespace.rb b/app/models/concerns/storage/legacy_namespace.rb index 99dbd4fbacf..b12c10a84de 100644 --- a/app/models/concerns/storage/legacy_namespace.rb +++ b/app/models/concerns/storage/legacy_namespace.rb @@ -87,20 +87,10 @@ module Storage remove_exports! end - def remove_exports! - Gitlab::Popen.popen(%W(find #{export_path} -not -path #{export_path} -delete)) - end - - def export_path - File.join(Gitlab::ImportExport.storage_path, full_path_was) - end + def remove_legacy_exports! + legacy_export_path = File.join(Gitlab::ImportExport.storage_path, full_path_was) - def full_path_was - if parent - parent.full_path + '/' + path_was - else - path_was - end + FileUtils.rm_rf(legacy_export_path) end end end diff --git a/app/models/group.rb b/app/models/group.rb index 62b1322ebe6..5b7f1b38612 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -274,12 +274,6 @@ class Group < Namespace list_of_ids.reverse.map { |group| variables[group.id] }.compact.flatten end - def full_path_was - return path_was unless has_parent? - - "#{parent.full_path}/#{path_was}" - end - def group_member(user) if group_members.loaded? group_members.find { |gm| gm.user_id == user.id } diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 5010dd73c11..7b82d076975 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -221,6 +221,24 @@ class Namespace < ActiveRecord::Base has_parent? end + def full_path_was + return path_was unless has_parent? + + "#{parent.full_path}/#{path_was}" + end + + # Exports belonging to projects with legacy storage are placed in a common + # subdirectory of the namespace, so a simple `rm -rf` is sufficient to remove + # them. + # + # Exports of projects using hashed storage are placed in a location defined + # only by the project ID, so each must be removed individually. + def remove_exports! + remove_legacy_exports! + + all_projects.with_storage_feature(:repository).find_each(&:remove_exports) + end + private def refresh_access_of_projects_invited_groups diff --git a/app/models/project.rb b/app/models/project.rb index 03c5475c31f..12d5f28f5ea 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -69,6 +69,7 @@ class Project < ActiveRecord::Base before_destroy :remove_private_deploy_keys after_destroy -> { run_after_commit { remove_pages } } + after_destroy :remove_exports after_validation :check_pending_delete @@ -1525,6 +1526,8 @@ class Project < ActiveRecord::Base end def export_path + return nil unless namespace.present? || hashed_storage?(:repository) + File.join(Gitlab::ImportExport.storage_path, disk_path) end @@ -1533,8 +1536,9 @@ class Project < ActiveRecord::Base end def remove_exports - _, status = Gitlab::Popen.popen(%W(find #{export_path} -not -path #{export_path} -delete)) - status.zero? + return nil unless export_path.present? + + FileUtils.rm_rf(export_path) end def full_path_slug |