Commit ecc9a263 authored by Jacob Vosmaer's avatar Jacob Vosmaer
Browse files

Route path lookups through legacy_disk_path

parent 88f6382fff90
......@@ -96,7 +96,7 @@ def key_restriction_options_for_select(type)
def repository_storages_options_for_select(selected)
options = Gitlab.config.repositories.storages.map do |name, storage|
["#{name} - #{storage['path']}", name]
["#{name} - #{storage.legacy_disk_path}", name]
end
options_for_select(options, selected)
......
......@@ -498,7 +498,7 @@ def empty_repo?
end
def repository_storage_path
Gitlab.config.repositories.storages[repository_storage].try(:[], 'path')
Gitlab.config.repositories.storages[repository_storage]&.legacy_disk_path
end
def team
......
......@@ -467,12 +467,7 @@ def cron_for_usage_ping
end
Settings.repositories.storages.each do |key, storage|
storage = Settingslogic.new(storage)
# Expand relative paths
storage['path'] = Settings.absolute(storage['path'])
Settings.repositories.storages[key] = storage
Settings.repositories.storages[key] = Gitlab::GitalyClient::StorageSettings.new(storage)
end
#
......@@ -486,7 +481,7 @@ def cron_for_usage_ping
repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(%r{/$}, '')
repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home'])
if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(%r{/$}, '')) }
if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs.legacy_disk_path.gsub(%r{/$}, '')) }
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive')
end
......
......@@ -5,7 +5,7 @@ def storage_name_valid?(name)
def find_parent_path(name, path)
parent = Pathname.new(path).realpath.parent
Gitlab.config.repositories.storages.detect do |n, rs|
name != n && Pathname.new(rs['path']).realpath == parent
name != n && Pathname.new(rs.legacy_disk_path).realpath == parent
end
rescue Errno::EIO, Errno::ENOENT => e
warning = "WARNING: couldn't verify #{path} (#{name}). "\
......@@ -33,7 +33,7 @@ def validate_storages_config
"If you're using the Gitlab Development Kit, you can update your configuration running `gdk reconfigure`.\n"
end
if !repository_storage.is_a?(Hash) || repository_storage['path'].nil?
if !repository_storage.is_a?(Gitlab::GitalyClient::StorageSettings) || repository_storage.legacy_disk_path.nil?
storage_validation_error("#{name} is not a valid storage, because it has no `path` key. Refer to gitlab.yml.example for an updated example")
end
......@@ -50,7 +50,7 @@ def validate_storages_config
def validate_storages_paths
Gitlab.config.repositories.storages.each do |name, repository_storage|
parent_name, _parent_path = find_parent_path(name, repository_storage['path'])
parent_name, _parent_path = find_parent_path(name, repository_storage.legacy_disk_path)
if parent_name
storage_validation_error("#{name} is a nested path of #{parent_name}. Nested paths are not supported for repository storages")
end
......
......@@ -12,7 +12,7 @@ def self.find_including_path(id)
end
def repository_storage_path
Gitlab.config.repositories.storages[repository_storage]['path']
Gitlab.config.repositories.storages[repository_storage].legacy_disk_path
end
def repository_path
......
......@@ -60,7 +60,7 @@ def rename_path(path)
def move_namespace(group_id, path_was, path)
repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{group_id}").map do |row|
Gitlab.config.repositories.storages[row['repository_storage']]['path']
Gitlab.config.repositories.storages[row['repository_storage']].legacy_disk_path
end.compact
# Move the namespace directory in all storages paths used by member projects
......
......@@ -71,7 +71,7 @@ def check_routes(base, counter, path)
route_exists = route_exists?(path)
Gitlab.config.repositories.storages.each_value do |storage|
if route_exists || path_exists?(path, storage['path'])
if route_exists || path_exists?(path, storage.legacy_disk_path)
counter += 1
path = "#{base}#{counter}"
......@@ -84,7 +84,7 @@ def check_routes(base, counter, path)
def move_namespace(namespace_id, path_was, path)
repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{namespace_id}").map do |row|
Gitlab.config.repositories.storages[row['repository_storage']]['path']
Gitlab.config.repositories.storages[row['repository_storage']].legacy_disk_path
end.compact
# Move the namespace directory in all storages paths used by member projects
......
......@@ -65,7 +65,7 @@ def dump
def restore
Gitlab.config.repositories.storages.each do |name, repository_storage|
path = repository_storage['path']
path = repository_storage.legacy_disk_path
next unless File.exist?(path)
# Move repos dir to 'repositories.old' dir
......@@ -200,7 +200,7 @@ def empty_repo?(project_or_wiki)
end
def repository_storage_paths_args
Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
Gitlab.config.repositories.storages.values.map { |rs| rs.legacy_disk_path }
end
def progress
......
......@@ -74,7 +74,7 @@ class Project < ActiveRecord::Base
}.freeze
def repository_storage_path
Gitlab.config.repositories.storages[repository_storage]['path']
Gitlab.config.repositories.storages[repository_storage].legacy_disk_path
end
# Overridden to have the correct `source_type` for the `route` relation
......
......@@ -212,7 +212,7 @@ def shard_name
end
def shard_name_from_shard_path(shard_path)
Gitlab.config.repositories.storages.find { |_, info| info['path'] == shard_path }&.first ||
Gitlab.config.repositories.storages.find { |_, info| info.legacy_disk_path == shard_path }&.first ||
raise(ShardNameNotFoundError, "no shard found for path '#{shard_path}'")
end
......
......@@ -93,7 +93,7 @@ def initialize(storage, relative_path, gl_repository)
@relative_path = relative_path
@gl_repository = gl_repository
storage_path = Gitlab.config.repositories.storages[@storage]['path']
storage_path = Gitlab.config.repositories.storages[@storage].legacy_disk_path
@gitlab_projects = Gitlab::Git::GitlabProjects.new(
storage_path,
relative_path,
......
......@@ -35,7 +35,7 @@ def self.check_histogram
def initialize(storage, logger = Rails.logger)
@storage = storage
config = Gitlab.config.repositories.storages[@storage]
@storage_path = config['path']
@storage_path = config.legacy_disk_path
@logger = logger
@hostname = Gitlab::Environment.hostname
......
......@@ -25,7 +25,7 @@ def self.build(storage, hostname = Gitlab::Environment.hostname)
if !config.present?
NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Storage '#{storage}' is not configured"))
elsif !config['path'].present?
elsif !config.legacy_disk_path.present?
NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Path for storage '#{storage}' is not configured"))
else
new(storage, hostname)
......
module Gitlab
module GitalyClient
# This is a chokepoint that is meant to help us stop remove all places
# where production code (app, config, db, lib) touches Git repositories
# directly.
class StorageSettings
DirectPathAccessError = Class.new(StandardError)
# This class will give easily recognizable NoMethodErrors
Deprecated = Class.new
attr_reader :legacy_disk_path
def initialize(storage)
raise "expected a Hash, got a #{storage.class.name}" unless storage.is_a?(Hash)
# Support a nil 'path' field because some of the circuit breaker tests use it.
@legacy_disk_path = File.expand_path(storage['path'], Rails.root) if storage['path']
storage['path'] = Deprecated
@hash = storage
end
def gitaly_address
@hash.fetch(:gitaly_address)
end
private
def method_missing(m, *args, &block)
@hash.public_send(m, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
......@@ -77,7 +77,7 @@ def with_temp_file(storage_name)
end
def storage_path(storage_name)
storages_paths&.dig(storage_name, 'path')
storages_paths[storage_name]&.legacy_disk_path
end
# All below test methods use shell commands to perform actions on storage volumes.
......
......@@ -21,11 +21,11 @@ def self.strip_storage_path(repo_path, fail_on_not_found: true)
result = repo_path
storage = Gitlab.config.repositories.storages.values.find do |params|
repo_path.start_with?(params['path'])
repo_path.start_with?(params.legacy_disk_path)
end
if storage
result = result.sub(storage['path'], '')
result = result.sub(storage.legacy_disk_path, '')
elsif fail_on_not_found
raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
end
......
......@@ -24,7 +24,7 @@ def gitaly_configuration_toml(gitaly_dir, gitaly_ruby: true)
address = val['gitaly_address']
end
storages << { name: key, path: val['path'] }
storages << { name: key, path: val.legacy_disk_path }
end
if Rails.env.test?
......
......@@ -81,7 +81,7 @@ def add_repository(storage, name)
repository.gitaly_repository_client.create_repository
true
else
repo_path = File.join(Gitlab.config.repositories.storages[storage]['path'], relative_path)
repo_path = File.join(Gitlab.config.repositories.storages[storage].legacy_disk_path, relative_path)
Gitlab::Git::Repository.create(repo_path, bare: true, symlink_hooks_to: gitlab_shell_hooks_path)
end
end
......@@ -130,7 +130,7 @@ def fetch_remote(repository, remote, ssh_auth: nil, forced: false, no_tags: fals
if is_enabled
repository.gitaly_repository_client.fetch_remote(remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, timeout: git_timeout, prune: prune)
else
storage_path = Gitlab.config.repositories.storages[repository.storage]["path"]
storage_path = Gitlab.config.repositories.storages[repository.storage].legacy_disk_path
local_fetch_remote(storage_path, repository.relative_path, remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, prune: prune)
end
end
......@@ -477,7 +477,7 @@ def gitlab_shell_fast_execute_helper(cmd, vars = {})
def gitaly_namespace_client(storage_path)
storage, _value = Gitlab.config.repositories.storages.find do |storage, value|
value['path'] == storage_path
value.legacy_disk_path == storage_path
end
Gitlab::GitalyClient::NamespaceService.new(storage)
......
......@@ -129,7 +129,7 @@ def warn_user_is_not_gitlab
def all_repos
Gitlab.config.repositories.storages.each_value do |repository_storage|
IO.popen(%W(find #{repository_storage['path']} -mindepth 2 -type d -name *.git)) do |find|
IO.popen(%W(find #{repository_storage.legacy_disk_path} -mindepth 2 -type d -name *.git)) do |find|
find.each_line do |path|
yield path.chomp
end
......@@ -138,7 +138,7 @@ def all_repos
end
def repository_storage_paths_args
Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
Gitlab.config.repositories.storages.values.map { |rs| rs.legacy_disk_path }
end
def user_home
......
......@@ -6,8 +6,8 @@ class NamespaceCheck < SystemCheck::BaseCheck
def multi_check
Gitlab.config.repositories.storages.each do |storage_name, repository_storage|
$stdout.puts
$stdout.puts "* Storage: #{storage_name} (#{repository_storage['path']})".color(:yellow)
toplevel_namespace_dirs = disk_namespaces(repository_storage['path'])
$stdout.puts "* Storage: #{storage_name} (#{repository_storage.legacy_disk_path})".color(:yellow)
toplevel_namespace_dirs = disk_namespaces(repository_storage.legacy_disk_path)
orphans = (toplevel_namespace_dirs - existing_namespaces)
print_orphans(orphans, storage_name)
......
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