summaryrefslogtreecommitdiff
path: root/app/models/storage/legacy_project.rb
blob: 928c773c3073b5e7d51435e5a1a9b4e7a201bb1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

module Storage
  class LegacyProject
    attr_accessor :project
    delegate :namespace, :gitlab_shell, :repository_storage, to: :project

    def initialize(project)
      @project = project
    end

    # Base directory
    #
    # @return [String] directory where repository is stored
    def base_dir
      namespace.full_path
    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
      project.full_path
    end

    def ensure_storage_path_exists
      return unless namespace

      gitlab_shell.add_namespace(repository_storage, base_dir)
    end

    def rename_repo(old_full_path: nil, new_full_path: nil)
      old_full_path ||= project.full_path_before_last_save
      new_full_path ||= project.build_full_path

      if gitlab_shell.mv_repository(repository_storage, old_full_path, new_full_path)
        # If repository moved successfully we need to send update instructions to users.
        # However we cannot allow rollback since we moved repository
        # So we basically we mute exceptions in next actions
        begin
          gitlab_shell.mv_repository(repository_storage, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
          return true
        rescue => e
          Rails.logger.error "Exception renaming #{old_full_path} -> #{new_full_path}: #{e}" # rubocop:disable Gitlab/RailsLogger
          # Returning false does not rollback after_* transaction but gives
          # us information about failing some of tasks
          return false
        end
      end

      false
    end
  end
end