Class: Installation::UpgradeRepoManager
- Inherits:
-
Object
- Object
- Installation::UpgradeRepoManager
- 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
-
#repositories ⇒ Array<Y2Packager::Repository>
readonly
The old repositories.
-
#services ⇒ Array<Y2Packager::Repository>
readonly
The old services.
Class Method Summary collapse
Instance Method Summary collapse
-
#activate_changes ⇒ Object
Activate the changes.
-
#change_url(repo, url) ⇒ Object
Change the URL of a repository.
-
#initialize(old_repositories, old_services) ⇒ UpgradeRepoManager
constructor
Constructor.
-
#repo_status(repo) ⇒ Symbol?
Return the configured status of a repository.
-
#repo_url(repo) ⇒ String
Return the repository URL, if it was changed by the user than the new URL is returned.
-
#toggle_repo_status(repo) ⇒ Symbol?
Toggle the repository status.
Constructor Details
#initialize(old_repositories, old_services) ⇒ UpgradeRepoManager
Constructor
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
#repositories ⇒ Array<Y2Packager::Repository> (readonly)
Returns The old repositories.
32 33 34 |
# File 'src/lib/installation/upgrade_repo_manager.rb', line 32 def repositories @repositories end |
#services ⇒ Array<Y2Packager::Repository> (readonly)
Returns 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_repositories ⇒ Object
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_changes ⇒ Object
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 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'src/lib/installation/upgrade_repo_manager.rb', line 124 def activate_changes update_urls process_repos remove_services # reload the package manager to activate the changes, # remember the selected products/packages (ignore the dependencies selected by solver) selected = Y2Packager::Resolvable.find(status: :selected, transact_by: :appl_high) Yast::Pkg.SourceSaveAll Yast::Pkg.SourceFinishAll Yast::Pkg.SourceRestore Yast::Pkg.SourceLoad # restore the selection selected.each { |s| Yast::Pkg.ResolvableInstall(s.name, s.kind) } end |
#change_url(repo, url) ⇒ Object
Change the URL of a repository.
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.
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.
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->...
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 |