2018-08-10 02:45:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-01 22:11:35 -04:00
|
|
|
module Storage
|
2020-02-04 07:09:00 -05:00
|
|
|
class Hashed
|
2020-02-13 10:08:52 -05:00
|
|
|
attr_accessor :container
|
|
|
|
delegate :gitlab_shell, :repository_storage, to: :container
|
2017-08-17 11:39:18 -04:00
|
|
|
|
2018-11-20 06:48:18 -05:00
|
|
|
REPOSITORY_PATH_PREFIX = '@hashed'
|
2020-04-22 08:09:29 -04:00
|
|
|
GROUP_REPOSITORY_PATH_PREFIX = '@groups'
|
2020-02-13 10:08:52 -05:00
|
|
|
SNIPPET_REPOSITORY_PATH_PREFIX = '@snippets'
|
2018-11-20 06:48:18 -05:00
|
|
|
POOL_PATH_PREFIX = '@pools'
|
2017-08-07 05:07:42 -04:00
|
|
|
|
2020-02-13 10:08:52 -05:00
|
|
|
def initialize(container, prefix: REPOSITORY_PATH_PREFIX)
|
|
|
|
@container = container
|
2018-11-20 06:48:18 -05:00
|
|
|
@prefix = prefix
|
2017-08-07 05:07:42 -04:00
|
|
|
end
|
2017-08-01 22:11:35 -04:00
|
|
|
|
2017-08-04 01:30:42 -04:00
|
|
|
# Base directory
|
|
|
|
#
|
|
|
|
# @return [String] directory where repository is stored
|
|
|
|
def base_dir
|
2018-11-20 06:48:18 -05:00
|
|
|
"#{@prefix}/#{disk_hash[0..1]}/#{disk_hash[2..3]}" if disk_hash
|
2017-08-01 22:11:35 -04:00
|
|
|
end
|
|
|
|
|
2020-02-13 10:08:52 -05:00
|
|
|
# Disk path is used to build repository path on disk
|
2017-08-04 01:30:42 -04:00
|
|
|
#
|
2020-02-13 10:08:52 -05:00
|
|
|
# @return [String] combination of base_dir and the repository own name
|
|
|
|
# without `.git`, `.wiki.git`, or any other extension
|
2017-08-01 22:11:35 -04:00
|
|
|
def disk_path
|
2017-08-15 22:49:54 -04:00
|
|
|
"#{base_dir}/#{disk_hash}" if disk_hash
|
2017-08-01 22:11:35 -04:00
|
|
|
end
|
|
|
|
|
2019-01-21 22:33:32 -05:00
|
|
|
def rename_repo(old_full_path: nil, new_full_path: nil)
|
2017-08-15 22:49:54 -04:00
|
|
|
true
|
2017-08-01 22:11:35 -04:00
|
|
|
end
|
2017-08-04 01:30:42 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-13 10:08:52 -05:00
|
|
|
# Generates the hash for the repository path and name on disk
|
2017-08-04 01:30:42 -04:00
|
|
|
# If you need to refer to the repository on disk, use the `#disk_path`
|
|
|
|
def disk_hash
|
2020-02-13 10:08:52 -05:00
|
|
|
@disk_hash ||= Digest::SHA2.hexdigest(container.id.to_s) if container.id
|
2017-08-04 01:30:42 -04:00
|
|
|
end
|
2017-08-01 22:11:35 -04:00
|
|
|
end
|
|
|
|
end
|