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