From 34d14f5ea8cc67f2e217a8a6d38b831629cf9d4e Mon Sep 17 00:00:00 2001
From: Michael Schroeder <mls@suse.de>
Date: Thu, 19 Sep 2024 15:34:58 +0200
Subject: [PATCH] Take conflicts into account when resolving direct
 dependencies

---
 Build/Expand.pm | 1 +
 t/conflicts.t   | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/Build/Expand.pm b/Build/Expand.pm
index 93332038d..97c18ebcb 100644
--- a/Build/Expand.pm
+++ b/Build/Expand.pm
@@ -465,6 +465,7 @@ sub expand {
       next;
     }
     my @q = @{$whatprovides->{$r} || Build::addproviders($config, $r)};
+    @q = grep {!$aconflicts{$_}} @q if @q > 1;
     my $pn = $r;
     $pn =~ s/ .*//;
     @q = grep {$_ eq $pn} @q;
diff --git a/t/conflicts.t b/t/conflicts.t
index 2dbb99f4c..3dd8dfd71 100644
--- a/t/conflicts.t
+++ b/t/conflicts.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 15;
+use Test::More tests => 16;
 
 require 't/testlib.pm';
 
@@ -31,6 +31,8 @@ C: m
 P: x = 1-1
 P: y = 1-1
 R: x
+P: z = 1-1 z1
+P: z2 = 1-1 z
 EOR
 
 my $config = setuptest($repo, "Conflict: i:j\nConflict: x");
@@ -85,3 +87,6 @@ is_deeply(\@r, [undef, 'x is in conflict'], 'install x');
 
 @r = expand($config, 'y');
 is_deeply(\@r, [undef, '(provider x is in conflict)', 'conflict for providers of x needed by y'], 'install y');
+
+@r = expand($config, 'z', '!z1');
+is_deeply(\@r, [1, 'z2'], 'install z !z1');