summaryrefslogtreecommitdiff
path: root/lib/gitlab/repo_path.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-03-24 16:54:22 +0100
committerJacob Vosmaer <jacob@gitlab.com>2017-03-29 14:48:04 +0200
commitc837da34391094b9d58763a67db5cfb706ca146f (patch)
treef8e37a66ab012b2a6ec0c40c18b7eb366b6b5c09 /lib/gitlab/repo_path.rb
parentb46ac16cc89d649bf5fba9a36f1911a575b41e1f (diff)
downloadgitlab-ce-c837da34391094b9d58763a67db5cfb706ca146f.tar.gz
Helper method for storage path stripping
Diffstat (limited to 'lib/gitlab/repo_path.rb')
-rw-r--r--lib/gitlab/repo_path.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/gitlab/repo_path.rb b/lib/gitlab/repo_path.rb
new file mode 100644
index 00000000000..4b1d828c45c
--- /dev/null
+++ b/lib/gitlab/repo_path.rb
@@ -0,0 +1,23 @@
+module Gitlab
+ module RepoPath
+ NotFoundError = Class.new(StandardError)
+
+ def self.strip_storage_path(repo_path)
+ result = nil
+
+ Gitlab.config.repositories.storages.values.each do |params|
+ storage_path = params['path']
+ if repo_path.start_with?(storage_path)
+ result = repo_path.sub(storage_path, '')
+ break
+ end
+ end
+
+ if result.nil?
+ raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
+ end
+
+ result.sub(/\A\/*/, '')
+ end
+ end
+end