debian-mirror-gitlab/app/models/storage/hashed.rb

47 lines
1.2 KiB
Ruby
Raw Normal View History

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