Read about our upcoming Code of Conduct on this issue

legacy_project.rb 1.96 KB
Newer Older
1
2
# frozen_string_literal: true

3
module Storage
4
5
  class LegacyProject
    attr_accessor :project
6
    delegate :namespace, :gitlab_shell, :repository_storage, to: :project
7
8
9
10

    def initialize(project)
      @project = project
    end
11

12
13
14
15
16
17
18
19
20
21
    # 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
22
    def disk_path
23
      project.full_path
24
25
    end

26
27
28
29
    # 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.
30
    def ensure_storage_path_exists
31
32
      return unless namespace

33
      true
34
35
    end

36
    def rename_repo(old_full_path: nil, new_full_path: nil)
37
      old_full_path ||= project.full_path_before_last_save
38
      new_full_path ||= project.build_full_path
39

40
      if gitlab_shell.mv_repository(repository_storage, old_full_path, new_full_path)
41
42
43
44
        # 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
45
          gitlab_shell.mv_repository(repository_storage, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
46
          return true
47
        rescue => e
Mayra Cabrera's avatar
Mayra Cabrera committed
48
          Rails.logger.error "Exception renaming #{old_full_path} -> #{new_full_path}: #{e}" # rubocop:disable Gitlab/RailsLogger
49
50
          # Returning false does not rollback after_* transaction but gives
          # us information about failing some of tasks
51
          return false
52
53
54
        end
      end

55
      false
56
57
58
    end
  end
end