Commit a1cd9be4 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'git-fsck-worker-client-prep' into 'master'

Move SingleRepositoryWorker#fsck into Gitlab::Git::Repository

Closes gitaly#802

See merge request gitlab-org/gitlab-ce!15710
parents 0f3f50d1 12f61e0d
...@@ -32,16 +32,14 @@ module RepositoryCheck ...@@ -32,16 +32,14 @@ module RepositoryCheck
end end
def git_fsck(repository) def git_fsck(repository)
path = repository.path_to_repo return false unless repository.exists?
cmd = %W(nice git --git-dir=#{path} fsck)
output, status = Gitlab::Popen.popen(cmd)
if status.zero? repository.raw_repository.fsck
true
else true
Gitlab::RepositoryCheckLogger.error("command failed: #{cmd.join(' ')}\n#{output}") rescue Gitlab::Git::Repository::GitError => e
false Gitlab::RepositoryCheckLogger.error(e.message)
end false
end end
def has_pushes?(project) def has_pushes?(project)
......
...@@ -1118,9 +1118,11 @@ module Gitlab ...@@ -1118,9 +1118,11 @@ module Gitlab
end end
# Refactoring aid; allows us to copy code from app/models/repository.rb # Refactoring aid; allows us to copy code from app/models/repository.rb
def run_git(args, env: {}) def run_git(args, env: {}, nice: false)
cmd = [Gitlab.config.git.bin_path, *args]
cmd.unshift("nice") if nice
circuit_breaker.perform do circuit_breaker.perform do
popen([Gitlab.config.git.bin_path, *args], path, env) popen(cmd, path, env)
end end
end end
...@@ -1187,6 +1189,12 @@ module Gitlab ...@@ -1187,6 +1189,12 @@ module Gitlab
end end
end end
def fsck
output, status = run_git(%W[--git-dir=#{path} fsck], nice: true)
raise GitError.new("Could not fsck repository:\n#{output}") unless status.zero?
end
def gitaly_repository def gitaly_repository
Gitlab::GitalyClient::Util.repository(@storage, @relative_path, @gl_repository) Gitlab::GitalyClient::Util.repository(@storage, @relative_path, @gl_repository)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment