Call `Snippets::RepositoryValidationService` when restoring snippet in backup
We need to call the Snippets::RepositoryValidationService
to ensure that the restored repository is valid.
For that, we can change the Backup::Repositories#restore
method to:
def restore
Project.find_each(batch_size: 1000) do |project|
restore_repository(project, Gitlab::GlRepository::PROJECT)
restore_repository(project, Gitlab::GlRepository::WIKI)
restore_repository(project, Gitlab::GlRepository::DESIGN)
end
Snippet.find_each(batch_size: 1000) do |snippet|
restore_snippet_repository(snippet)
end
restore_object_pools
end
And then add the restore_snippet_repository
like:
def restore_snippet_repository(snippet)
restore_repository(snippet, Gitlab::GlRepository::SNIPPET)
response = Snippets::RepositoryValidationService.new(nil, snippet).execute
if response.error?
repository.remove
snippet.snippet_repository.delete # Maybe this line is not necessary since we remove the snippet
snippet.delete
progress.puts("Snippet #{snippet.full_path} can't be restored: #{response.message}")
end
end
To test it we can just untar a backup file, and copy a project repository to the snippet repository folder replacing the name with the snippet one.
Edited by Francisco Javier López (ex-Gitlab)