diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2017-08-02 05:11:35 +0300 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2017-08-22 07:33:20 +0300 |
commit | 53403399577bdca0e8f0886fa62ce0e75c14a8e0 (patch) | |
tree | 4ba58b5848ef0ba9fb07ce88ec7a0a40564187b6 /app | |
parent | 950c87308aa7e9f3ae5bf84790d30d6fcb688fc8 (diff) |
Add UUID Storage to Project
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/storage/uuid_project.rb | 58 | ||||
-rw-r--r-- | app/models/project.rb | 9 |
2 files changed, 66 insertions, 1 deletions
diff --git a/app/models/concerns/storage/uuid_project.rb b/app/models/concerns/storage/uuid_project.rb new file mode 100644 index 00000000000..8a73287e518 --- /dev/null +++ b/app/models/concerns/storage/uuid_project.rb @@ -0,0 +1,58 @@ +module Storage + module UUIDProject + extend ActiveSupport::Concern + + def uuid_dir + %Q(#{uuid[0..1]}/#{uuid[2..3]}) + end + + def disk_path + %Q(#{uuid_dir}/#{uuid}) + end + + def ensure_storage_path_exist + gitlab_shell.add_namespace(repository_storage_path, uuid_dir) + end + + def rename_repo + # TODO: We cannot wipe most of this method until we provide migration path for Container Registries + path_was = previous_changes['path'].first + old_path_with_namespace = File.join(namespace.full_path, path_was) + new_path_with_namespace = File.join(namespace.full_path, path) + + Rails.logger.error "Attempting to rename #{old_path_with_namespace} -> #{new_path_with_namespace}" + + if has_container_registry_tags? + Rails.logger.error "Project #{old_path_with_namespace} cannot be renamed because container registry tags are present!" + + # we currently doesn't support renaming repository if it contains images in container registry + raise StandardError.new('Project cannot be renamed, because images are present in its container registry') + end + + begin + # TODO: we can avoid cache expiration if cache is based on UUID or just project_id + expire_caches_before_rename(old_path_with_namespace) + expires_full_path_cache + + send_move_instructions(old_path_with_namespace) + + @old_path_with_namespace = old_path_with_namespace + + SystemHooksService.new.execute_hooks_for(self, :rename) + + @repository = nil + rescue => e + Rails.logger.error "Exception renaming #{old_path_with_namespace} -> #{new_path_with_namespace}: #{e}" + # Returning false does not rollback after_* transaction but gives + # us information about failing some of tasks + false + end + + Gitlab::AppLogger.info "Project was renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}" + + # TODO: When we move Uploads and Pages to use UUID we can disable this transfers as well + Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.full_path) + Gitlab::PagesTransfer.new.rename_project(path_was, path, namespace.full_path) + end + end +end diff --git a/app/models/project.rb b/app/models/project.rb index 570955e81dd..f0ea83dda0c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -17,7 +17,6 @@ class Project < ActiveRecord::Base include ProjectFeaturesCompatibility include SelectForProjectAuthorization include Routable - include Storage::LegacyProject extend Gitlab::ConfigHelper @@ -1424,6 +1423,14 @@ class Project < ActiveRecord::Base private + def load_storage + if self.storage_version > 1 + self.class.include Storage::UUIDProject + else + self.class.include Storage::LegacyProject + end + end + # set last_activity_at to the same as created_at def set_last_activity_at update_column(:last_activity_at, self.created_at) |