From 9ff82d8428423e2319f13b1de55dc42190edf047 Mon Sep 17 00:00:00 2001
From: Oleg Ogurtsov <o.ogurtsov@samsung.com>
Date: Wed, 4 Oct 2017 16:53:29 +0300
Subject: [PATCH] [backend] Use all paths for expanded searching (not only
 last)

---
 src/backend/BSSched/ProjPacks.pm | 24 ++++++++++----------
 src/backend/bs_srcserver         | 47 ++++++++++++++++++++--------------------
 2 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/src/backend/BSSched/ProjPacks.pm b/src/backend/BSSched/ProjPacks.pm
index ed138a5..05d13b1 100644
--- a/src/backend/BSSched/ProjPacks.pm
+++ b/src/backend/BSSched/ProjPacks.pm
@@ -759,20 +759,18 @@ sub expandsearchpath {
     push @ret, $t unless $done{$prp};
     $done{$prp} = 1;
     BSSched::Remote::addwatchremote($gctx, 'repository', $t->{'project'}, "/$t->{'repository'}/$myarch") unless $t->{'repository'} eq '_unavailable';
-    if (!@path) {
-      last if $done{"/$prp"};
-      my ($pid, $rid) = ($t->{'project'}, $t->{'repository'});
-      my $proj = BSSched::Remote::addwatchremote($gctx, 'project', $pid, '');
-      if ($proj) {
-        $proj = BSSched::Remote::fetchremoteproj($gctx, $proj, $pid);
-      } else {
-        $proj = $projpacks->{$pid};
-      }
-      next unless $proj;
-      $done{"/$prp"} = 1;       # mark expanded
-      my @repo = grep {$_->{'name'} eq $rid} @{$proj->{'repository'} || []};
-      push @path, @{$repo[0]->{'path'}} if @repo && $repo[0]->{'path'};
+    next if $done{"/$prp"};
+    my ($pid, $rid) = ($t->{'project'}, $t->{'repository'});
+    my $proj = BSSched::Remote::addwatchremote($gctx, 'project', $pid, '');
+    if ($proj) {
+      $proj = BSSched::Remote::fetchremoteproj($gctx, $proj, $pid);
+    } else {
+      $proj = $projpacks->{$pid};
     }
+    next unless $proj;
+    $done{"/$prp"} = 1;       # mark expanded
+    my @repo = grep {$_->{'name'} eq $rid} @{$proj->{'repository'} || []};
+    push @path, @{$repo[0]->{'path'}} if @repo && $repo[0]->{'path'};
   }
   return @ret;
 }
diff --git a/src/backend/bs_srcserver b/src/backend/bs_srcserver
index d78e9e4..41f92a0 100755
--- a/src/backend/bs_srcserver
+++ b/src/backend/bs_srcserver
@@ -2126,33 +2126,34 @@ sub expandsearchpath {
     my $prp = "$t->{'project'}/$t->{'repository'}";
     push @ret, $prp unless $done{$prp};
     $done{$prp} = 1;
-    if (!@path) {
-      ($base->{'project'}, $base->{'repository'}) = ($t->{'project'}, $t->{'repository'}) if $base;
-      last if $done{"/$prp"};
-      my ($pid, $tid) = ($t->{'project'}, $t->{'repository'});
-      my $proj = BSRevision::readproj_local($pid, 1);
-      if (!$proj || $proj->{'remoteurl'}) {
-	undef $proj;
-	$proj = $remotemap->{$pid} if $remotemap && $remotemap->{$pid};
-	if (!$proj || $proj->{'proto'}) {
-          $proj = BSSrcServer::Remote::remoteprojid($pid);
-          $proj = BSSrcServer::Remote::fetchremoteproj($proj, $pid, $remotemap);
-          die("404 project '$pid' does not exist\n") unless $proj;
-        }
-      }
-      BSSrcServer::Partition::checkpartition($remotemap, $pid, $proj) if $remotemap && $remotemap->{':partitions'} && !$remotemap->{':partitions'}->{$pid};
-      $done{"/$prp"} = 1;       # mark expanded
-      my @repo = grep {$_->{'name'} eq $tid} @{$proj->{'repository'} || []};
-      push @path, @{$repo[0]->{'path'}} if @repo && $repo[0]->{'path'};
-    } elsif ($remotemap) {
-      my $pid = $t->{'project'};
-      my $proj = BSRevision::readproj_local($pid, 1);
-      if ((!$proj || $proj->{'remoteurl'}) && !$remotemap->{$pid}) {
+
+    my $pid = $t->{'project'};
+    my $proj = BSRevision::readproj_local($pid, 1);
+
+    ($base->{'project'}, $base->{'repository'}) = ($t->{'project'}, $t->{'repository'}) if $base;
+    next if $done{"/$prp"};
+
+    if ((!$proj || $proj->{'remoteurl'}) && !$remotemap->{$pid}) {
         my $r = BSSrcServer::Remote::remoteprojid($pid);
         $remotemap->{$pid} = {%$r, 'proto' => 1} if $r;
+    }
+    BSSrcServer::Partition::checkpartition($remotemap, $pid, $proj) if $remotemap && $remotemap->{':partitions'} && !$remotemap->{':partitions'}->{$pid};
+
+    if (!$proj || $proj->{'remoteurl'}) {
+      undef $proj;
+      $proj = $remotemap->{$pid} if $remotemap && $remotemap->{$pid};
+      if (!$proj || $proj->{'proto'}) {
+        $proj = BSSrcServer::Remote::remoteprojid($pid);
+        $proj = BSSrcServer::Remote::fetchremoteproj($proj, $pid, $remotemap);
+        die("404 project '$pid' does not exist\n") unless $proj;
       }
-      BSSrcServer::Partition::checkpartition($remotemap, $pid, $proj) if $remotemap && $remotemap->{':partitions'} && !$remotemap->{':partitions'}->{$pid};
     }
+    BSSrcServer::Partition::checkpartition($remotemap, $pid, $proj) if $remotemap && $remotemap->{':partitions'} && !$remotemap->{':partitions'}->{$pid};
+
+    $done{"/$prp"} = 1;       # mark expanded
+    my $tid = $t->{'repository'};
+    my @repo = grep {$_->{'name'} eq $tid} @{$proj->{'repository'} || []};
+    push @path, @{$repo[0]->{'path'}} if @repo && $repo[0]->{'path'};
   }
   return @ret;
 }
-- 
2.7.4

