Class: Installation::UpdateRepository
- Inherits:
-
Object
- Object
- Installation::UpdateRepository
- Includes:
- Yast::I18n, Yast::Logger
- Defined in:
- src/lib/installation/update_repository.rb
Overview
Represents a update repository to be used during self-update (check doc/SELF_UPDATE.md for details).
Defined Under Namespace
Classes: CouldNotBeApplied, CouldNotExtractPackage, CouldNotFetchUpdate, CouldNotMountUpdate, CouldNotProbeRepo, CouldNotRefreshRepo, CouldNotSquashPackage, FetchError, NotValidRepo, PackageNotFound, UnknownOrigin, UpdatesNotFetched
Constant Summary collapse
- ORIGINS =
Where the repository information comes from
- :default: Default
- :user: User defined
[:default, :user].freeze
- INSTSYS_PARTS_PATH =
Path to instsys.parts registry
Pathname("/etc/instsys.parts")
- PACKAGE_INDEX =
a file with list of applied packages
"/.packages.self_update".freeze
Instance Attribute Summary collapse
-
#origin ⇒ Symbol
readonly
Repository origin.
-
#repo_id ⇒ Fixnum
readonly
Returns the repository ID.
-
#updates_file ⇒ Array<Pathname>
readonly
Squash filesystem path.
-
#uri ⇒ URI
readonly
URI of the repository.
Instance Method Summary collapse
-
#apply(mount_path = Pathname("/mounts")) ⇒ Object
Apply updates to inst-sys.
-
#cleanup ⇒ Object
Clean-up.
-
#empty? ⇒ Boolean
Determine whether the repository is empty or not.
-
#fetch(path = Pathname("/download")) ⇒ Pathname
Fetch updates and save them in a squasfs filesystem.
-
#initialize(uri, origin = :default) ⇒ UpdateRepository
constructor
Constructor.
-
#inspect ⇒ String
Redefines the inspect method to avoid logging passwords.
-
#packages ⇒ Array<Y2Packager::Resolvable>
Retrieves the list of packages to unpack to the inst-sys.
-
#remote? ⇒ Boolean
Determines whether the URI of the repository is remote or not.
-
#user_defined? ⇒ Boolean
Returns whether is a user defined repository.
Constructor Details
#initialize(uri, origin = :default) ⇒ UpdateRepository
Constructor
121 122 123 124 125 126 127 128 129 130 |
# File 'src/lib/installation/update_repository.rb', line 121 def initialize(uri, origin = :default) textdomain "installation" @uri = uri @updates_file = nil @packages = nil raise UnknownOrigin unless ORIGINS.include?(origin) @origin = origin end |
Instance Attribute Details
#origin ⇒ Symbol (readonly)
Returns Repository origin. @see ORIGINS.
68 69 70 |
# File 'src/lib/installation/update_repository.rb', line 68 def origin @origin end |
#repo_id ⇒ Fixnum
Returns the repository ID
As a potential side-effect, the repository will be added to libzypp (if it was not added yet) in order to get the ID.
140 141 142 |
# File 'src/lib/installation/update_repository.rb', line 140 def repo_id add_repo end |
#updates_file ⇒ Array<Pathname> (readonly)
Returns squash filesystem path.
66 67 68 |
# File 'src/lib/installation/update_repository.rb', line 66 def updates_file @updates_file end |
#uri ⇒ URI (readonly)
Returns URI of the repository.
64 65 66 |
# File 'src/lib/installation/update_repository.rb', line 64 def uri @uri end |
Instance Method Details
#apply(mount_path = Pathname("/mounts")) ⇒ Object
Apply updates to inst-sys
It happens in two phases (for each update/package):
- Mount the squashfs filesystem
- Add files/directories to inst-sys using the /sbin/adddir script
220 221 222 223 224 225 226 227 228 |
# File 'src/lib/installation/update_repository.rb', line 220 def apply(mount_path = Pathname("/mounts")) raise UpdatesNotFetched if updates_file.nil? mountpoint = next_name(mount_path, length: 4) mount_squashfs(updates_file, mountpoint) adddir(mountpoint) update_instsys_parts(updates_file, mountpoint) write_package_index end |
#cleanup ⇒ Object
Clean-up
Release the repository
233 234 235 236 237 238 |
# File 'src/lib/installation/update_repository.rb', line 233 def cleanup Yast::Pkg.SourceReleaseAll Yast::Pkg.SourceDelete(repo_id) # make sure it's also removed from disk Yast::Pkg.SourceSaveAll end |
#empty? ⇒ Boolean
Determine whether the repository is empty or not
243 244 245 |
# File 'src/lib/installation/update_repository.rb', line 243 def empty? Y2Packager::Resolvable.none?(kind: :package, source: repo_id) end |
#fetch(path = Pathname("/download")) ⇒ Pathname
Fetch updates and save them in a squasfs filesystem
Updates will be stored in the given directory.
If a known error occurs, it will be converted to a CouldNotFetchUpdate exception.
A progress is displayed when the packages are downloaded.
The progress can be disabled by calling Yast::Progress.set(false)
.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'src/lib/installation/update_repository.rb', line 191 def fetch(path = Pathname("/download")) init_progress Dir.mktmpdir do |workdir| packages.each_with_index do |package, index| update_progress(100 * index / packages.size) fetch_and_extract_package(package, workdir) end @updates_file = build_squashfs(workdir, next_name(path, length: 3)) end rescue Y2Packager::PackageFetchError, Y2Packager::PackageExtractionError, CouldNotSquashPackage => e log.error("Could not fetch update: #{e.inspect}. Rolling back.") raise CouldNotFetchUpdate end |
#inspect ⇒ String
Redefines the inspect method to avoid logging passwords
268 269 270 |
# File 'src/lib/installation/update_repository.rb', line 268 def inspect "#<Installation::UpdateRepository> @uri=\"#{safe_uri}\" @origin=#{@origin.inspect}" end |
#packages ⇒ Array<Y2Packager::Resolvable>
Retrieves the list of packages to unpack to the inst-sys
Only packages in the update repository are considered, meta-packages which should be used in an add-on and not applied to the inst-sys are ignored. The packages are sorted by name (alphabetical order). Additionally, only the latest version is considered.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'src/lib/installation/update_repository.rb', line 153 def packages return @packages unless @packages.nil? add_repo all_packages = Y2Packager::Resolvable.find(kind: :package, source: repo_id) pkg_names = all_packages.map(&:name).uniq # find the highest version of each package @packages = pkg_names.map do |name| all_packages.select { |p| p.name == name }.max do |a, b| Yast::Pkg.CompareVersions(a.version, b.version) end end log.info "Found #{@packages.size} packages: #{@packages.map(&:name)}" # remove packages which are used as addons, these should not be applied to the inst-sys addon_pkgs = Y2Packager::SelfUpdateAddonFilter.packages(repo_id) @packages.reject! { |p| addon_pkgs.include?(p.name) } log.info "Using #{@packages.size} packages: #{@packages.map(&:name)}" @packages end |
#remote? ⇒ Boolean
Determines whether the URI of the repository is remote or not
261 262 263 |
# File 'src/lib/installation/update_repository.rb', line 261 def remote? Yast::Pkg.UrlSchemeIsRemote(uri.scheme) end |
#user_defined? ⇒ Boolean
Returns whether is a user defined repository
251 252 253 |
# File 'src/lib/installation/update_repository.rb', line 251 def user_defined? origin == :user end |