BigW Consortium Gitlab

hashed_project.rb 1.11 KB
Newer Older
1
module Storage
2 3
  class HashedProject
    attr_accessor :project
4 5 6
    delegate :gitlab_shell, :repository_storage_path, to: :project

    ROOT_PATH_PREFIX = '@hashed'.freeze
7
    STORAGE_VERSION = 1
8 9 10 11

    def initialize(project)
      @project = project
    end
12

13 14 15 16
    # Base directory
    #
    # @return [String] directory where repository is stored
    def base_dir
17
      "#{ROOT_PATH_PREFIX}/#{disk_hash[0..1]}/#{disk_hash[2..3]}" if disk_hash
18 19
    end

20 21 22
    # 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
23
    def disk_path
24
      "#{base_dir}/#{disk_hash}" if disk_hash
25 26
    end

27
    def ensure_storage_path_exists
28
      gitlab_shell.add_namespace(repository_storage_path, base_dir)
29 30 31
    end

    def rename_repo
32
      true
33
    end
34 35 36 37 38 39

    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
40
      @disk_hash ||= Digest::SHA2.hexdigest(project.id.to_s) if project.id
41
    end
42 43
  end
end