Read about our upcoming Code of Conduct on this issue

hashed_project.rb 1.49 KB
Newer Older
1
2
# frozen_string_literal: true

Gabriel Mazetto's avatar
Gabriel Mazetto committed
3
module Storage
4
5
  class HashedProject
    attr_accessor :project
6
    delegate :gitlab_shell, :repository_storage, to: :project
7

8
9
    REPOSITORY_PATH_PREFIX = '@hashed'
    POOL_PATH_PREFIX = '@pools'
10

11
    def initialize(project, prefix: REPOSITORY_PATH_PREFIX)
12
      @project = project
13
      @prefix = prefix
14
    end
Gabriel Mazetto's avatar
Gabriel Mazetto committed
15

16
17
18
19
    # Base directory
    #
    # @return [String] directory where repository is stored
    def base_dir
20
      "#{@prefix}/#{disk_hash[0..1]}/#{disk_hash[2..3]}" if disk_hash
Gabriel Mazetto's avatar
Gabriel Mazetto committed
21
22
    end

23
24
25
    # 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
Gabriel Mazetto's avatar
Gabriel Mazetto committed
26
    def disk_path
27
      "#{base_dir}/#{disk_hash}" if disk_hash
Gabriel Mazetto's avatar
Gabriel Mazetto committed
28
29
    end

30
31
32
33
    # TODO: remove this method entirely after 12.4 https://gitlab.com/gitlab-org/gitlab/issues/33244
    # we no longer need ensure_storage_path_exists to call add_namespace since both creating and moving
    # repositories will be preceded by a mkdir -p in gitaly to ensure the parent of the destination directory
    # exists.
34
    def ensure_storage_path_exists
35
      true
Gabriel Mazetto's avatar
Gabriel Mazetto committed
36
37
    end

38
    def rename_repo(old_full_path: nil, new_full_path: nil)
39
      true
Gabriel Mazetto's avatar
Gabriel Mazetto committed
40
    end
41
42
43
44
45
46

    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
47
      @disk_hash ||= Digest::SHA2.hexdigest(project.id.to_s) if project.id
48
    end
Gabriel Mazetto's avatar
Gabriel Mazetto committed
49
50
  end
end