Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
cc28abea
Commit
cc28abea
authored
Sep 05, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect orphaned repositories and namespaces in any storage
parent
021724ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
0 deletions
+117
-0
lib/system_check/orphans/namespace_check.rb
lib/system_check/orphans/namespace_check.rb
+37
-0
lib/system_check/orphans/repository_check.rb
lib/system_check/orphans/repository_check.rb
+50
-0
lib/tasks/gitlab/check.rake
lib/tasks/gitlab/check.rake
+30
-0
No files found.
lib/system_check/orphans/namespace_check.rb
0 → 100644
View file @
cc28abea
module
SystemCheck
module
Orphans
class
NamespaceCheck
<
SystemCheck
::
BaseCheck
set_name
'Orphaned namespaces:'
def
multi_check
Gitlab
.
config
.
repositories
.
storages
.
each
do
|
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
)}
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
end
clear_namespaces!
# releases memory when check finishes
end
private
def
existing_namespaces
@namespaces
||=
Namespace
.
all
.
pluck
(
:path
)
end
def
clear_namespaces!
@namespaces
=
nil
end
end
end
end
lib/system_check/orphans/repository_check.rb
0 → 100644
View file @
cc28abea
module
SystemCheck
module
Orphans
class
RepositoryCheck
<
SystemCheck
::
BaseCheck
set_name
'Orphaned repositories:'
def
multi_check
Gitlab
.
config
.
repositories
.
storages
.
each
do
|
name
,
repository_storage
|
$stdout
.
puts
$stdout
.
puts
"* 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!
)
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
end
end
private
def
list_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)
WHERE (p.repository_storage LIKE ?)
"
query
=
ActiveRecord
::
Base
.
send
(
:sanitize_sql_array
,
[
sql
,
storage_name
])
ActiveRecord
::
Base
.
connection
.
select_all
(
query
).
rows
.
try
(
:flatten!
)
end
def
toplevel_namespace_dirs
(
storage_path
)
Dir
.
glob
(
File
.
join
(
storage_path
,
'*'
))
end
end
end
end
lib/tasks/gitlab/check.rake
View file @
cc28abea
...
...
@@ -398,6 +398,36 @@ namespace :gitlab do
end
end
namespace
:orphans
do
desc
'Gitlab | Check for orphaned namespaces and repositories'
task
check: :environment
do
warn_user_is_not_gitlab
checks
=
[
SystemCheck
::
Orphans
::
NamespaceCheck
,
SystemCheck
::
Orphans
::
RepositoryCheck
]
SystemCheck
.
run
(
'Orphans'
,
checks
)
end
desc
'GitLab | Check for orphaned namespaces in the repositories path'
task
check_namespaces: :environment
do
warn_user_is_not_gitlab
checks
=
[
SystemCheck
::
Orphans
::
NamespaceCheck
]
SystemCheck
.
run
(
'Orphans'
,
checks
)
end
desc
'GitLab | Check for orphaned repositories in the repositories path'
task
check_repositories: :environment
do
warn_user_is_not_gitlab
checks
=
[
SystemCheck
::
Orphans
::
RepositoryCheck
]
SystemCheck
.
run
(
'Orphans'
,
checks
)
end
end
namespace
:user
do
desc
"GitLab | Check the integrity of a specific user's repositories"
task
:check_repos
,
[
:username
]
=>
:environment
do
|
t
,
args
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment