summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-12-04 10:31:13 +0100
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-12-04 15:57:20 +0100
commit12f61e0d2cabb07172ef93143b084104141dd771 (patch)
tree27692688b55c3febe22122f1d18aa5c80bea47d0
parente0f84130567dc34edf1ae75fcf595e24991d2fa9 (diff)
downloadgitlab-ce-12f61e0d2cabb07172ef93143b084104141dd771.tar.gz
Move SingleRepositoryWorker#fsck into Gitlab::Git::Repository
-rw-r--r--app/workers/repository_check/single_repository_worker.rb16
-rw-r--r--lib/gitlab/git/repository.rb12
2 files changed, 17 insertions, 11 deletions
diff --git a/app/workers/repository_check/single_repository_worker.rb b/app/workers/repository_check/single_repository_worker.rb
index 164586cf0b7..3d4bee15f1c 100644
--- a/app/workers/repository_check/single_repository_worker.rb
+++ b/app/workers/repository_check/single_repository_worker.rb
@@ -32,16 +32,14 @@ module RepositoryCheck
end
def git_fsck(repository)
- path = repository.path_to_repo
- cmd = %W(nice git --git-dir=#{path} fsck)
- output, status = Gitlab::Popen.popen(cmd)
+ return false unless repository.exists?
- if status.zero?
- true
- else
- Gitlab::RepositoryCheckLogger.error("command failed: #{cmd.join(' ')}\n#{output}")
- false
- end
+ repository.raw_repository.fsck
+
+ true
+ rescue Gitlab::Git::Repository::GitError => e
+ Gitlab::RepositoryCheckLogger.error(e.message)
+ false
end
def has_pushes?(project)
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index dbc08747228..867fc2a42f6 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1118,9 +1118,11 @@ module Gitlab
end
# 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
- popen([Gitlab.config.git.bin_path, *args], path, env)
+ popen(cmd, path, env)
end
end
@@ -1187,6 +1189,12 @@ module Gitlab
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
Gitlab::GitalyClient::Util.repository(@storage, @relative_path, @gl_repository)
end