Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system_check/orphans/repository_check.rb')
-rw-r--r--lib/system_check/orphans/repository_check.rb58
1 files changed, 38 insertions, 20 deletions
diff --git a/lib/system_check/orphans/repository_check.rb b/lib/system_check/orphans/repository_check.rb
index 1de6bec165b..9b6b2429783 100644
--- a/lib/system_check/orphans/repository_check.rb
+++ b/lib/system_check/orphans/repository_check.rb
@@ -2,49 +2,67 @@ module SystemCheck
module Orphans
class RepositoryCheck < SystemCheck::BaseCheck
set_name 'Orphaned repositories:'
+ attr_accessor :orphans
def multi_check
- Gitlab.config.repositories.storages.each do |name, repository_storage|
+ Gitlab.config.repositories.storages.each do |storage_name, repository_storage|
$stdout.puts
- $stdout.puts "* Storage: #{name} (#{repository_storage['path']})".color(:yellow)
+ $stdout.puts "* Storage: #{storage_name} (#{repository_storage['path']})".color(:yellow)
- repositories = toplevel_namespace_dirs(repository_storage['path']).map do |path|
- namespace = File.basename(path)
- Dir.glob(File.join(path, '*')).map {|repo| "#{namespace}/#{File.basename(repo)}"}
- end.try(:flatten!)
+ repositories = disk_repositories(repository_storage['path'])
+ orphans = (repositories - fetch_repositories(storage_name))
- orphans = (repositories - list_repositories(name))
- if orphans.empty?
- $stdout.puts "* No orphaned repositories for #{name} storage".color(:green)
- next
- end
-
- orphans.each do |orphan|
- $stdout.puts " - #{orphan}".color(:red)
- end
+ print_orphans(orphans, storage_name)
end
end
private
- def list_repositories(storage_name)
+ def print_orphans(orphans, storage_name)
+ if orphans.empty?
+ $stdout.puts "* No orphaned repositories for #{storage_name} storage".color(:green)
+ return
+ end
+
+ orphans.each do |orphan|
+ $stdout.puts " - #{orphan}".color(:red)
+ end
+ end
+
+ def disk_repositories(storage_path)
+ fetch_disk_namespaces(storage_path).each_with_object([]) do |namespace_path, result|
+ namespace = File.basename(namespace_path)
+ next if namespace.eql?('@hashed')
+
+ fetch_disk_repositories(namespace_path).each do |repo|
+ result << "#{namespace}/#{File.basename(repo)}"
+ end
+ end
+ end
+
+ def fetch_repositories(storage_name)
sql = "
SELECT
CONCAT(n.path, '/', p.path, '.git') repo,
CONCAT(n.path, '/', p.path, '.wiki.git') wiki
FROM projects p
JOIN namespaces n
- ON (p.namespace_id = n.id)
+ ON (p.namespace_id = n.id AND
+ n.parent_id IS NULL)
WHERE (p.repository_storage LIKE ?)
"
- query = ActiveRecord::Base.send(:sanitize_sql_array, [sql, storage_name])
- ActiveRecord::Base.connection.select_all(query).rows.try(:flatten!)
+ query = ActiveRecord::Base.send(:sanitize_sql_array, [sql, storage_name]) # rubocop:disable GitlabSecurity/PublicSend
+ ActiveRecord::Base.connection.select_all(query).rows.try(:flatten!) || []
end
- def toplevel_namespace_dirs(storage_path)
+ def fetch_disk_namespaces(storage_path)
Dir.glob(File.join(storage_path, '*'))
end
+
+ def fetch_disk_repositories(namespace_path)
+ Dir.glob(File.join(namespace_path, '*'))
+ end
end
end
end