2017-09-05 01:05:23 -04:00
|
|
|
module SystemCheck
|
|
|
|
module Orphans
|
|
|
|
class NamespaceCheck < SystemCheck::BaseCheck
|
|
|
|
set_name 'Orphaned namespaces:'
|
|
|
|
|
|
|
|
def multi_check
|
2017-09-12 00:57:22 -04:00
|
|
|
Gitlab.config.repositories.storages.each do |storage_name, repository_storage|
|
2017-09-05 01:05:23 -04:00
|
|
|
$stdout.puts
|
2017-09-12 00:57:22 -04:00
|
|
|
$stdout.puts "* Storage: #{storage_name} (#{repository_storage['path']})".color(:yellow)
|
|
|
|
toplevel_namespace_dirs = disk_namespaces(repository_storage['path'])
|
2017-09-05 01:05:23 -04:00
|
|
|
|
|
|
|
orphans = (toplevel_namespace_dirs - existing_namespaces)
|
2017-09-12 00:57:22 -04:00
|
|
|
print_orphans(orphans, storage_name)
|
2017-09-05 01:05:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
clear_namespaces! # releases memory when check finishes
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-09-12 00:57:22 -04:00
|
|
|
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
|
|
|
|
|
2017-09-05 01:05:23 -04:00
|
|
|
def existing_namespaces
|
2017-09-12 00:57:22 -04:00
|
|
|
@namespaces ||= Namespace.where(parent: nil).all.pluck(:path)
|
2017-09-05 01:05:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def clear_namespaces!
|
|
|
|
@namespaces = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|