Class: Installation::UpgradeRepoManager

Inherits:
Object
  • Object
show all
Extended by:
Yast::Logger
Includes:
Yast::Logger
Defined in:
src/lib/installation/upgrade_repo_manager.rb

Overview

This class takes care of managing the old repositories and services during upgrade. It takes care of modifying the old repositories and using them in the new upgraded system.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_repositories, old_services) ⇒ UpgradeRepoManager

Constructor

Parameters:

  • old_repositories (Array<Y2Packager::Repository>)

    the old repositories which should be managed

  • old_services (Array<Y2Packager::Service>)

    the old services which should be managed



42
43
44
45
46
47
48
# File 'src/lib/installation/upgrade_repo_manager.rb', line 42

def initialize(old_repositories, old_services)
  @repositories = old_repositories
  @services = old_services
  @new_urls = {}
  # by default remove all repositories
  @status_map = repositories.map { |r| [r, :removed] }.to_h
end

Instance Attribute Details

#repositoriesArray<Y2Packager::Repository> (readonly)

Returns The old repositories.

Returns:

  • (Array<Y2Packager::Repository>)

    The old repositories



32
33
34
# File 'src/lib/installation/upgrade_repo_manager.rb', line 32

def repositories
  @repositories
end

#servicesArray<Y2Packager::Repository> (readonly)

Returns The old services.

Returns:

  • (Array<Y2Packager::Repository>)

    The old services



34
35
36
# File 'src/lib/installation/upgrade_repo_manager.rb', line 34

def services
  @services
end

Class Method Details

.create_from_old_repositoriesObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'src/lib/installation/upgrade_repo_manager.rb', line 50

def self.create_from_old_repositories
  # Find the current repositories for the old ones,
  # the repositories might have been changed during the upgrade
  # workflow by other clients, this ensures we use the current data.
  current_repos = Y2Packager::Repository.all
  stored_repos = Y2Packager::OriginalRepositorySetup.instance.repositories
  stored_repo_aliases = stored_repos.map(&:repo_alias)
  # exclude the newly added repositories with the same alias
  stored_repo_aliases -= Y2Packager::NewRepositorySetup.instance.repositories
  reg_urls = registration_urls

  old_repos = current_repos.select do |r|
    stored_repo_aliases.include?(r.repo_alias) &&
      !reg_urls.include?(base_url(r.raw_url.uri))
  end

  current_services = Y2Packager::Service.all
  stored_services = Y2Packager::OriginalRepositorySetup.instance.services
  stored_service_aliases = stored_services.map(&:alias)
  # exclude the newly added services with the same name
  stored_service_aliases -= Y2Packager::NewRepositorySetup.instance.services
  old_services = current_services.select { |s| stored_service_aliases.include?(s.alias) }

  # sort the repositories by name
  new(old_repos.sort_by(&:name), old_services)
end

Instance Method Details

#activate_changesObject

Activate the changes. This will enable/disable the repositories, set the new URLs and remove old services without saving the changes. To make the changes permanent (saved to disk) call YaST::Pkg.SourceSaveAll after calling this method.



124
125
126
127
128
# File 'src/lib/installation/upgrade_repo_manager.rb', line 124

def activate_changes
  update_urls
  process_repos
  remove_services
end

#change_url(repo, url) ⇒ Object

Change the URL of a repository.

Parameters:

  • repo (Y2Packager::Repository)

    The repository

  • url (String)

    Its new URL



116
117
118
# File 'src/lib/installation/upgrade_repo_manager.rb', line 116

def change_url(repo, url)
  new_urls[repo] = url if repo.raw_url.to_s != url
end

#repo_status(repo) ⇒ Symbol?

Return the configured status of a repository.

Parameters:

  • repo (Y2Packager::Repository)

    the repository

Returns:

  • (Symbol, nil)

    :removed, :enabled or :disabled symbol, nil if the repository is not known



81
82
83
# File 'src/lib/installation/upgrade_repo_manager.rb', line 81

def repo_status(repo)
  status_map[repo]
end

#repo_url(repo) ⇒ String

Return the repository URL, if it was changed by the user than the new URL is returned.

Parameters:

  • repo (Y2Packager::Repository)

    The queried repository

Returns:

  • (String)

    The URL



90
91
92
# File 'src/lib/installation/upgrade_repo_manager.rb', line 90

def repo_url(repo)
  new_urls[repo] || repo.url.to_s
end

#toggle_repo_status(repo) ⇒ Symbol?

Toggle the repository status. It cycles the repository status in this order: Removed->Enabled->Disabled->Removed->Enabled->Disabled->...

Parameters:

  • repo (Y2Packager::Repository)

    the repository

Returns:

  • (Symbol, nil)

    :removed, :enabled or :disabled symbol, nil if the repository is not known



101
102
103
104
105
106
107
108
109
110
# File 'src/lib/installation/upgrade_repo_manager.rb', line 101

def toggle_repo_status(repo)
  case repo_status(repo)
  when :enabled
    status_map[repo] = :disabled
  when :disabled
    status_map[repo] = :removed
  when :removed
    status_map[repo] = :enabled
  end
end