BigW Consortium Gitlab

legacy_project.rb 1.57 KB
Newer Older
1
module Storage
2 3 4 5 6 7 8
  class LegacyProject
    attr_accessor :project
    delegate :namespace, :gitlab_shell, :repository_storage_path, to: :project

    def initialize(project)
      @project = project
    end
9

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

24
    def ensure_storage_path_exists
25 26
      return unless namespace

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

    def rename_repo
31
      new_full_path = project.build_full_path
32

33
      if gitlab_shell.mv_repository(repository_storage_path, project.full_path_was, new_full_path)
34 35 36 37
        # 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
38 39
          gitlab_shell.mv_repository(repository_storage_path, "#{project.full_path_was}.wiki", "#{new_full_path}.wiki")
          return true
40
        rescue => e
41
          Rails.logger.error "Exception renaming #{project.full_path_was} -> #{new_full_path}: #{e}"
42 43
          # Returning false does not rollback after_* transaction but gives
          # us information about failing some of tasks
44
          return false
45 46 47
        end
      end

48
      false
49 50 51
    end
  end
end