diff options
Diffstat (limited to 'lib/system_check/orphans/namespace_check.rb')
-rw-r--r-- | lib/system_check/orphans/namespace_check.rb | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/lib/system_check/orphans/namespace_check.rb b/lib/system_check/orphans/namespace_check.rb index 1963cbfc985..b8446300f72 100644 --- a/lib/system_check/orphans/namespace_check.rb +++ b/lib/system_check/orphans/namespace_check.rb @@ -4,20 +4,13 @@ module SystemCheck set_name 'Orphaned namespaces:' 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) - toplevel_namespace_dirs = Dir.glob(File.join(repository_storage['path'], '*')).map{|p| File.basename(p)} + $stdout.puts "* Storage: #{storage_name} (#{repository_storage['path']})".color(:yellow) + toplevel_namespace_dirs = disk_namespaces(repository_storage['path']) orphans = (toplevel_namespace_dirs - existing_namespaces) - if orphans.empty? - $stdout.puts "* No orphaned namespaces for #{name} storage".color(:green) - next - end - - orphans.each do |orphan| - $stdout.puts " - #{orphan}".color(:red) - end + print_orphans(orphans, storage_name) end clear_namespaces! # releases memory when check finishes @@ -25,8 +18,32 @@ module SystemCheck private + def print_orphans(orphans, storage_name) + if orphans.empty? + $stdout.puts "* No orphaned namespaces for #{storage_name} storage".color(:green) + return + end + + orphans.each do |orphan| + $stdout.puts " - #{orphan}".color(:red) + end + end + + def disk_namespaces(storage_path) + fetch_disk_namespaces(storage_path).each_with_object([]) do |namespace_path, result| + namespace = File.basename(namespace_path) + next if namespace.eql?('@hashed') + + result << namespace + end + end + + def fetch_disk_namespaces(storage_path) + Dir.glob(File.join(storage_path, '*')) + end + def existing_namespaces - @namespaces ||= Namespace.all.pluck(:path) + @namespaces ||= Namespace.where(parent: nil).all.pluck(:path) end def clear_namespaces! |