summaryrefslogtreecommitdiff
path: root/app/models/storage
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2017-08-16 04:49:54 +0200
committerGabriel Mazetto <brodock@gmail.com>2017-08-22 06:33:20 +0200
commitd17a7be8308b06b7077a7cffc5d258148ee08c87 (patch)
tree3c5e5f47644f5d605649ee977654788d4f512739 /app/models/storage
parent78823675b24e82e73a523ad98f1dec78bec6976c (diff)
downloadgitlab-ce-d17a7be8308b06b7077a7cffc5d258148ee08c87.tar.gz
Refactor project and storage types
Diffstat (limited to 'app/models/storage')
-rw-r--r--app/models/storage/hashed_project.rb43
-rw-r--r--app/models/storage/legacy_project.rb45
2 files changed, 11 insertions, 77 deletions
diff --git a/app/models/storage/hashed_project.rb b/app/models/storage/hashed_project.rb
index e6d68a177fe..1a10e0e59a8 100644
--- a/app/models/storage/hashed_project.rb
+++ b/app/models/storage/hashed_project.rb
@@ -18,52 +18,15 @@ module Storage
#
# @return [String] combination of base_dir and the repository own name without `.git` or `.wiki.git` extensions
def disk_path
- "#{base_dir}/#{disk_hash}"
+ "#{base_dir}/#{disk_hash}" if disk_hash
end
- def ensure_storage_path_exist
+ def ensure_storage_path_exists
gitlab_shell.add_namespace(repository_storage_path, base_dir)
end
def rename_repo
- # TODO: We cannot wipe most of this method until we provide migration path for Container Registries
- path_was = project.previous_changes['path'].first
- old_path_with_namespace = File.join(namespace.full_path, path_was)
- new_path_with_namespace = File.join(namespace.full_path, project.path)
-
- Rails.logger.error "Attempting to rename #{old_path_with_namespace} -> #{new_path_with_namespace}"
-
- if project.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
- project.expire_caches_before_rename(old_path_with_namespace)
- project.expires_full_path_cache
-
- project.send_move_instructions(old_path_with_namespace)
-
- project.old_path_with_namespace = old_path_with_namespace
-
- SystemHooksService.new.execute_hooks_for(project, :rename)
-
- project.reload_repository!
- 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, project.path, namespace.full_path)
- Gitlab::PagesTransfer.new.rename_project(path_was, project.path, namespace.full_path)
+ true
end
private
diff --git a/app/models/storage/legacy_project.rb b/app/models/storage/legacy_project.rb
index b7b073ad077..9d9e5e1d352 100644
--- a/app/models/storage/legacy_project.rb
+++ b/app/models/storage/legacy_project.rb
@@ -21,60 +21,31 @@ module Storage
project.full_path
end
- def ensure_storage_path_exist
+ def ensure_storage_path_exists
return unless namespace
gitlab_shell.add_namespace(repository_storage_path, base_dir)
end
def rename_repo
- path_was = project.previous_changes['path'].first
- old_path_with_namespace = File.join(base_dir, path_was)
- new_path_with_namespace = File.join(base_dir, project.path)
+ new_full_path = project.build_full_path
- Rails.logger.error "Attempting to rename #{old_path_with_namespace} -> #{new_path_with_namespace}"
-
- if project.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
-
- project.expire_caches_before_rename(old_path_with_namespace)
-
- if gitlab_shell.mv_repository(repository_storage_path, old_path_with_namespace, new_path_with_namespace)
+ if gitlab_shell.mv_repository(repository_storage_path, project.full_path_was, new_full_path)
# If repository moved successfully we need to send update instructions to users.
# However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions
begin
- gitlab_shell.mv_repository(repository_storage_path, "#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki")
- project.send_move_instructions(old_path_with_namespace)
- project.expires_full_path_cache
-
- project.old_path_with_namespace = old_path_with_namespace
-
- SystemHooksService.new.execute_hooks_for(project, :rename)
-
- project.reload_repository!
+ gitlab_shell.mv_repository(repository_storage_path, "#{project.full_path_was}.wiki", "#{new_full_path}.wiki")
+ return true
rescue => e
- Rails.logger.error "Exception renaming #{old_path_with_namespace} -> #{new_path_with_namespace}: #{e}"
+ Rails.logger.error "Exception renaming #{project.full_path_was} -> #{new_full_path}: #{e}"
# Returning false does not rollback after_* transaction but gives
# us information about failing some of tasks
- false
+ return false
end
- else
- Rails.logger.error "Repository could not be renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}"
-
- # if we cannot move namespace directory we should rollback
- # db changes in order to prevent out of sync between db and fs
- raise StandardError.new('repository cannot be renamed')
end
- Gitlab::AppLogger.info "Project was renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}"
-
- Gitlab::UploadsTransfer.new.rename_project(path_was, project.path, base_dir)
- Gitlab::PagesTransfer.new.rename_project(path_was, project.path, base_dir)
+ false
end
end
end