Skip to content

Commit

Permalink
Merge pull request #815 from openSUSE/fix_pattern_selection
Browse files Browse the repository at this point in the history
Fix installing the user selected patterns
  • Loading branch information
lslezak authored Oct 25, 2023
2 parents 35b427c + 59656e8 commit 0d609c7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions service/lib/agama/software/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Manager
DEFAULT_LANGUAGES = ["en_US"].freeze
private_constant :DEFAULT_LANGUAGES

PROPOSAL_ID = "agama-user-software-selection"
private_constant :PROPOSAL_ID

attr_accessor :languages

# FIXME: what about defining a Product class?
Expand All @@ -75,8 +78,6 @@ def initialize(config, logger)
end
@repositories = RepositoriesManager.new
on_progress_change { logger.info progress.to_s }
# patterns selected by user
@user_patterns = []
@selected_patterns_change_callbacks = []
end

Expand Down Expand Up @@ -201,7 +202,7 @@ def add_pattern(id)
# TODO: error handling
res = Yast::Pkg.ResolvableInstall(id, :pattern)
logger.info "Adding pattern #{res.inspect}"
@user_patterns << id
Yast::PackagesProposal.AddResolvables(PROPOSAL_ID, :pattern, [id])

res = Yast::Pkg.PkgSolve(unused = true)
logger.info "Solver run #{res.inspect}"
Expand All @@ -212,17 +213,18 @@ def remove_pattern(id)
# TODO: error handling
res = Yast::Pkg.ResolvableNeutral(id, :pattern, force = false)
logger.info "Removing pattern #{res.inspect}"
@user_patterns.delete(id)
Yast::PackagesProposal.RemoveResolvables(PROPOSAL_ID, :pattern, [id])

res = Yast::Pkg.PkgSolve(unused = true)
logger.info "Solver run #{res.inspect}"
selected_patterns_changed
end

def user_patterns=(ids)
@user_patterns.each { |p| Yast::Pkg.ResolvableNeutral(p, :pattern, force = false) }
@user_patterns = ids
@user_patterns.each { |p| Yast::Pkg.ResolvableInstall(p, :pattern) }
user_patterns = Yast::PackagesProposal.GetResolvables(PROPOSAL_ID, :pattern)
user_patterns.each { |p| Yast::Pkg.ResolvableNeutral(p, :pattern, force = false) }
Yast::PackagesProposal.SetResolvables(PROPOSAL_ID, :pattern, ids)
ids.each { |p| Yast::Pkg.ResolvableInstall(p, :pattern) }
logger.info "Setting patterns to #{res.inspect}"

res = Yast::Pkg.PkgSolve(unused = true)
Expand All @@ -233,10 +235,12 @@ def user_patterns=(ids)
# @return [Array<Array<String>,Array<String>] returns pair of arrays where the first one
# is user selected pattern ids and in other is auto selected ones
def selected_patterns
user_patterns = Yast::PackagesProposal.GetResolvables(PROPOSAL_ID, :pattern)

patterns = Y2Packager::Resolvable.find(kind: :pattern, status: :selected)
patterns.map!(&:name)

patterns.partition { |p| @user_patterns.include?(p) }
patterns.partition { |p| user_patterns.include?(p) }
end

def on_selected_patterns_change(&block)
Expand Down

0 comments on commit 0d609c7

Please sign in to comment.