diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-03-24 18:54:22 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-03-29 15:48:04 +0300 |
commit | c837da34391094b9d58763a67db5cfb706ca146f (patch) | |
tree | f8e37a66ab012b2a6ec0c40c18b7eb366b6b5c09 /lib/gitlab/repo_path.rb | |
parent | b46ac16cc89d649bf5fba9a36f1911a575b41e1f (diff) |
Helper method for storage path stripping
Diffstat (limited to 'lib/gitlab/repo_path.rb')
-rw-r--r-- | lib/gitlab/repo_path.rb | 23 |
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 |