2018-05-28 05:58:14 -04:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class StorageService
|
|
|
|
def initialize(storage)
|
|
|
|
@storage = storage
|
|
|
|
end
|
|
|
|
|
Port cleanup tasks to use Gitaly
Rake tasks cleaning up the Git storage were still using direct disk
access, which won't work if these aren't attached. To mitigate a
migration issue was created.
To port gitlab:cleanup:dirs, and gitlab:cleanup:repos, a new RPC was
required, ListDirectories. This was implemented in Gitaly, through
https://gitlab.com/gitlab-org/gitaly/merge_requests/868.
To be able to use the new RPC the Gitaly server was bumped to v0.120.
This is an RPC that will not use feature gates, as this doesn't scale on
.com so there is no way to test it at scale. Futhermore, we _know_ it
doesn't scale, but this might be a useful task for smaller instances.
Lastly, the tests are slightly updated to also work when the disk isn't
attached. Eventhough this is not planned, it was very little effort and
thus I applied the boy scout rule.
Closes https://gitlab.com/gitlab-org/gitaly/issues/954
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/40529
2018-09-07 05:16:34 -04:00
|
|
|
# Returns all directories in the git storage directory, lexically ordered
|
|
|
|
def list_directories(depth: 1)
|
|
|
|
request = Gitaly::ListDirectoriesRequest.new(storage_name: @storage, depth: depth)
|
|
|
|
|
|
|
|
GitalyClient.call(@storage, :storage_service, :list_directories, request)
|
|
|
|
.flat_map(&:paths)
|
|
|
|
end
|
|
|
|
|
2018-05-28 05:58:14 -04:00
|
|
|
# Delete all repositories in the storage. This is a slow and VERY DESTRUCTIVE operation.
|
|
|
|
def delete_all_repositories
|
|
|
|
request = Gitaly::DeleteAllRepositoriesRequest.new(storage_name: @storage)
|
|
|
|
GitalyClient.call(@storage, :storage_service, :delete_all_repositories, request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|