Skip to content

Commit

Permalink
UpdateRepository#add_repo cannot return nil
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 14, 2017
1 parent 220938f commit a9bacdb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/installation/update_repository.rb
Expand Up @@ -56,6 +56,9 @@ class UpdateRepository
attr_reader :update_files
# @return [Symbol] Repository origin. @see ORIGINS
attr_reader :origin
# @return [Integer] Repository ID
attr_writer :repo_id
private :repo_id=

# A valid repository was not found (although the URL exists,
# repository type cannot be determined).
Expand Down Expand Up @@ -120,7 +123,6 @@ def initialize(uri, origin = :default)

# @return [Fixnum] yast2-pkg-bindings ID of the repository
def repo_id
return @repo_id unless @repo_id.nil?
add_repo
end

Expand All @@ -134,7 +136,7 @@ def repo_id
# @see Yast::Pkg.ResolvableProperties
def packages
return @packages unless @packages.nil?
add_repo if repo_id.nil?
add_repo
candidates = Yast::Pkg.ResolvableProperties("", :package, "")
@packages = candidates.select { |p| p["source"] == repo_id }.sort_by! { |a| a["name"] }
log.info "Considering #{@packages.size} packages: #{@packages}"
Expand Down Expand Up @@ -327,14 +329,15 @@ def build_squashfs(dir, file)
# @raise CouldNotProbeRepo
# @raise CouldNotRefreshRepo
def add_repo
return @repo_id unless @repo_id.nil?
status = repo_status
raise NotValidRepo if status == :not_found
raise CouldNotProbeRepo if status == :error
new_repo_id = Yast::Pkg.RepositoryAdd("base_urls" => [uri.to_s],
"enabled" => true, "autorefresh" => true)
log.info("Added repository #{uri} as '#{new_repo_id}'")
if Yast::Pkg.SourceRefreshNow(new_repo_id) && Yast::Pkg.SourceLoad
new_repo_id
self.repo_id = new_repo_id
else
log.error("Could not get metadata from repository '#{new_repo_id}'")
raise CouldNotRefreshRepo
Expand Down

0 comments on commit a9bacdb

Please sign in to comment.