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

43 lines
1.1 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
class HashedProject
attr_accessor :project
2018-10-15 14:42:47 +05:30
delegate :gitlab_shell, :repository_storage, to: :project
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
REPOSITORY_PATH_PREFIX = '@hashed'
POOL_PATH_PREFIX = '@pools'
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
def initialize(project, prefix: REPOSITORY_PATH_PREFIX)
2018-03-17 18:26:18 +05:30
@project = project
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
# 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
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
# 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
@disk_hash ||= Digest::SHA2.hexdigest(project.id.to_s) if project.id
end
end
end