Class: Installation::UpdatesManager

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

Overview

This class takes care of managing installer updates

Installer updates are distributed as rpm-md repositories. This class tries to offer a really simple API to get updates and apply them to inst-sys.

Examples:

Applying updates from one repository

manager = UpdatesManager.new
manager.add_repository(URI("http://update.opensuse.org/42.1"))
manager.apply_all

Applying updates from multiple repositories

manager = UpdatesManager.new
manager.add_repository(URI("http://update.opensuse.org/42.1"))
manager.add_repository(URI("http://example.net/leap"))
manager.apply_all

Defined Under Namespace

Classes: CouldNotFetchUpdateFromRepo, CouldNotProbeRepo, NotValidRepo, RepoError

Constant Summary collapse

DRIVER_UPDATES_PATHS =
[Pathname("/update"), Pathname("/download")].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(duds_paths = DRIVER_UPDATES_PATHS) ⇒ UpdatesManager

Constructor

At instantiation time, this class looks for existin driver updates in the given duds_path.

Parameters:

  • duds_paths (Pathname) (defaults to: DRIVER_UPDATES_PATHS)

    Path where driver updates are supposed to live



65
66
67
68
# File 'src/lib/installation/updates_manager.rb', line 65

def initialize(duds_paths = DRIVER_UPDATES_PATHS)
  @repositories = []
  @driver_updates = Installation::DriverUpdate.find(duds_paths)
end

Instance Attribute Details

#driver_updatesArray<DriverUpdate> (readonly)

Returns Driver updates found in inst-sys.

Returns:

  • (Array<DriverUpdate>)

    Driver updates found in inst-sys



42
43
44
# File 'src/lib/installation/updates_manager.rb', line 42

def driver_updates
  @driver_updates
end

#repositoriesArray<UpdateRepository> (readonly)

Returns Repositories containing updates.

Returns:



39
40
41
# File 'src/lib/installation/updates_manager.rb', line 39

def repositories
  @repositories
end

Instance Method Details

#add_repository(uri) ⇒ Boolean

Add an update repository

Most of exceptions coming from Installation::UpdateRepository are catched, except those that has something to do with applying the update itself (mounting or adding files to inst-sys). Check Installation::UpdateRepository::CouldNotMountUpdate and Installation::UpdateRepository::CouldNotBeApplied for more information.

Parameters:

  • uri (URI)

    URI where the repository lives

Returns:

  • (Boolean)

    true if the repository was added; false otherwise.

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'src/lib/installation/updates_manager.rb', line 83

def add_repository(uri)
  new_repository = Installation::UpdateRepository.new(uri)
  new_repository.fetch
  has_packages = !new_repository.empty?
  if has_packages
    repositories << new_repository
  else
    log.info("Update repository at #{uri} is empty. Skipping...")
  end
  has_packages
rescue Installation::UpdateRepository::NotValidRepo
  log.warn("Update repository at #{uri} could not be found")
  raise NotValidRepo
rescue Installation::UpdateRepository::FetchError
  log.error("Update repository at #{uri} was found but update could not be fetched")
  raise CouldNotFetchUpdateFromRepo
rescue Installation::UpdateRepository::CouldNotProbeRepo
  log.error("Update repository at #{uri} could not be read")
  raise CouldNotProbeRepo
end

#apply_allObject

Applies all the updates

It delegates the responsability of updating the inst-sys to added repositories and driver updates.

Raises:

  • CouldNotUpdateControlFile

See Also:



113
114
115
116
117
# File 'src/lib/installation/updates_manager.rb', line 113

def apply_all
  (repositories + driver_updates).each(&:apply)
  repositories.each(&:cleanup)
  replace_control_file
end

#repositories?Boolean

Determines whether the manager has repositories with updates

Returns:

  • (Boolean)


120
121
122
# File 'src/lib/installation/updates_manager.rb', line 120

def repositories?
  !repositories.empty?
end