Skip to content
Snippets Groups Projects
Commit bb9d360c authored by Sean McGivern's avatar Sean McGivern
Browse files

Merge branch 'mark-legacy-git-access' into 'master'

Route path lookups through legacy_disk_path

See merge request gitlab-org/gitlab-ce!17743
parents 963e445f 008a6a6c
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 34 deletions
Loading
Loading
@@ -96,7 +96,7 @@ module ApplicationSettingsHelper
 
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)
Loading
Loading
Loading
Loading
@@ -503,7 +503,7 @@ class Project < ActiveRecord::Base
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
Loading
Loading
Loading
Loading
@@ -467,12 +467,7 @@ unless Settings.repositories.storages['default']
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
 
#
Loading
Loading
@@ -486,7 +481,7 @@ repositories_storages = Settings.repositories.storages.values
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
 
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ end
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}). "\
Loading
Loading
@@ -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
 
Loading
Loading
@@ -50,7 +50,7 @@ end
 
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
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration
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
Loading
Loading
Loading
Loading
@@ -60,7 +60,7 @@ class RemoveDotGitFromGroupNames < ActiveRecord::Migration
 
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
Loading
Loading
Loading
Loading
@@ -71,7 +71,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
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}"
 
Loading
Loading
@@ -84,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
 
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
Loading
Loading
Loading
Loading
@@ -65,7 +65,7 @@ module Backup
 
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
Loading
Loading
@@ -200,7 +200,7 @@ module Backup
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
Loading
Loading
Loading
Loading
@@ -74,7 +74,7 @@ module Gitlab
}.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
Loading
Loading
Loading
Loading
@@ -212,7 +212,7 @@ module Gitlab
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
 
Loading
Loading
Loading
Loading
@@ -93,7 +93,7 @@ module Gitlab
@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,
Loading
Loading
Loading
Loading
@@ -35,7 +35,7 @@ module Gitlab
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
Loading
Loading
Loading
Loading
@@ -25,7 +25,7 @@ module Gitlab
 
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)
Loading
Loading
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
Loading
Loading
@@ -77,7 +77,7 @@ module Gitlab
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.
Loading
Loading
Loading
Loading
@@ -21,11 +21,11 @@ module Gitlab
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
Loading
Loading
Loading
Loading
@@ -24,7 +24,7 @@ module Gitlab
address = val['gitaly_address']
end
 
storages << { name: key, path: val['path'] }
storages << { name: key, path: val.legacy_disk_path }
end
 
if Rails.env.test?
Loading
Loading
Loading
Loading
@@ -82,7 +82,7 @@ module Gitlab
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
Loading
Loading
@@ -131,7 +131,7 @@ module Gitlab
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
Loading
Loading
@@ -478,7 +478,7 @@ module Gitlab
 
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)
Loading
Loading
Loading
Loading
@@ -129,7 +129,7 @@ module 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
Loading
Loading
@@ -138,7 +138,7 @@ module Gitlab
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
Loading
Loading
Loading
Loading
@@ -6,8 +6,8 @@ module SystemCheck
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)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment