diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-09-15 09:04:21 +0300 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-09-15 09:04:21 +0300 |
commit | 740d158019480f41d0b1e528d0d42c9441d2c2ac (patch) | |
tree | 593440a5df388437380869ea2038d13d33f4c8a3 /lib/system_check/orphans/namespace_check.rb | |
parent | 7533bda8a804e6c2d6054eef7a5c3c37c606ea21 (diff) | |
parent | d8bf06926eb67a02bea039261589df5fd2c2fbb6 (diff) |
Merge branch '10-0-stable-prepare-rc3' into '10-0-stable'
Prepare 10.0 RC3 release
See merge request gitlab-org/gitlab-ce!14266
Diffstat (limited to 'lib/system_check/orphans/namespace_check.rb')
-rw-r--r-- | lib/system_check/orphans/namespace_check.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/system_check/orphans/namespace_check.rb b/lib/system_check/orphans/namespace_check.rb new file mode 100644 index 00000000000..b8446300f72 --- /dev/null +++ b/lib/system_check/orphans/namespace_check.rb @@ -0,0 +1,54 @@ +module SystemCheck + module Orphans + class NamespaceCheck < SystemCheck::BaseCheck + set_name 'Orphaned namespaces:' + + 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']) + + orphans = (toplevel_namespace_dirs - existing_namespaces) + print_orphans(orphans, storage_name) + end + + clear_namespaces! # releases memory when check finishes + end + + 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.where(parent: nil).all.pluck(:path) + end + + def clear_namespaces! + @namespaces = nil + end + end + end +end |