BigW Consortium Gitlab

hashed_project.rb 1.09 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 8 9 10

    def initialize(project)
      @project = project
    end
11

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

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

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

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

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