Explorar o código

get sources for packages in multiple releases again

In 321213f0dcdcdaab04e01663e7a047b261400c9c Andreas Cadhalpun corrected
the incorrect overriding of earlier better-fitting results with later
(semi-)matches – but that broke the case in which packages are in multiple
releases in the same version (and the user has both releases configured).

Closes: 812497
David Kalnischkies %!s(int64=10) %!d(string=hai) anos
pai
achega
07aca07ae7

+ 14 - 16
apt-private/private-source.cc

@@ -122,7 +122,7 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
       return 0;
       return 0;
    }
    }
 
 
-   if (MatchSrcOnly == false && Pkg.end() == false) 
+   if (MatchSrcOnly == false && Pkg.end() == false)
    {
    {
       if(VerTag != "" || RelTag != "" || ArchTag != "")
       if(VerTag != "" || RelTag != "" || ArchTag != "")
       {
       {
@@ -176,7 +176,7 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
 	       // or we match against a release
 	       // or we match against a release
 	       if(VerTag.empty() == false ||
 	       if(VerTag.empty() == false ||
 		     (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
 		     (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
-		     (VF.File().Codename() != 0 && VF.File().Codename() == RelTag)) 
+		     (VF.File().Codename() != 0 && VF.File().Codename() == RelTag))
 	       {
 	       {
 		  // the Version we have is possibly fuzzy or includes binUploads,
 		  // the Version we have is possibly fuzzy or includes binUploads,
 		  // so we use the Version of the SourcePkg (empty if same as package)
 		  // so we use the Version of the SourcePkg (empty if same as package)
@@ -190,12 +190,12 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
 	 }
 	 }
       }
       }
 
 
-      if (Src == "" && ArchTag != "")
+      if (Src.empty() == true && ArchTag.empty() == false)
       {
       {
-	 if (VerTag != "")
+	 if (VerTag.empty() == false)
 	    _error->Error(_("Can not find a package '%s' with version '%s'"),
 	    _error->Error(_("Can not find a package '%s' with version '%s'"),
 		  Pkg.FullName().c_str(), VerTag.c_str());
 		  Pkg.FullName().c_str(), VerTag.c_str());
-	 if (RelTag != "")
+	 if (RelTag.empty() == false)
 	    _error->Error(_("Can not find a package '%s' with release '%s'"),
 	    _error->Error(_("Can not find a package '%s' with release '%s'"),
 		  Pkg.FullName().c_str(), RelTag.c_str());
 		  Pkg.FullName().c_str(), RelTag.c_str());
 	 Src = Name;
 	 Src = Name;
@@ -254,26 +254,24 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
    /* Iterate over all of the hits, which includes the resulting
    /* Iterate over all of the hits, which includes the resulting
       binary packages in the search */
       binary packages in the search */
 	       pkgSrcRecords::Parser *Parse;
 	       pkgSrcRecords::Parser *Parse;
-	       while (true) 
+	       while (true)
 	       {
 	       {
 		  SrcRecs.Restart();
 		  SrcRecs.Restart();
-		  while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0) 
+		  while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
 		  {
 		  {
 		     const std::string Ver = Parse->Version();
 		     const std::string Ver = Parse->Version();
-		     bool CorrectRelTag = false;
 
 
 		     // See if we need to look for a specific release tag
 		     // See if we need to look for a specific release tag
-		     if (RelTag != "" && UserRequestedVerTag == "")
+		     if (RelTag.empty() == false && UserRequestedVerTag.empty() == true)
 		     {
 		     {
 			pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(Cache, SrcList, Parse);
 			pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(Cache, SrcList, Parse);
 			if (Rls.end() == false)
 			if (Rls.end() == false)
 			{
 			{
-			   if ((Rls->Archive != 0 && RelTag == Rls.Archive()) ||
-				 (Rls->Codename != 0 && RelTag == Rls.Codename()))
-			      CorrectRelTag = true;
+			   if ((Rls->Archive != 0 && RelTag != Rls.Archive()) &&
+				 (Rls->Codename != 0 && RelTag != Rls.Codename()))
+			      continue;
 			}
 			}
-		     } else
-			CorrectRelTag = true;
+		     }
 
 
 		     // Ignore all versions which doesn't fit
 		     // Ignore all versions which doesn't fit
 		     if (VerTag.empty() == false &&
 		     if (VerTag.empty() == false &&
@@ -281,7 +279,7 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
 			continue;
 			continue;
 
 
 		     // Newer version or an exact match? Save the hit
 		     // Newer version or an exact match? Save the hit
-		     if (CorrectRelTag && (Last == 0 || Cache->VS().CmpVersion(Version,Ver) < 0)) {
+		     if (Last == 0 || Cache->VS().CmpVersion(Version,Ver) < 0) {
 			Last = Parse;
 			Last = Parse;
 			Offset = Parse->Offset();
 			Offset = Parse->Offset();
 			Version = Ver;
 			Version = Ver;
@@ -293,7 +291,7 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
 			break;
 			break;
 		  }
 		  }
 		  if (UserRequestedVerTag == "" && Version != "" && RelTag != "")
 		  if (UserRequestedVerTag == "" && Version != "" && RelTag != "")
-		     ioprintf(c1out, "Selected version '%s' (%s) for %s\n", 
+		     ioprintf(c1out, "Selected version '%s' (%s) for %s\n",
 			   Version.c_str(), RelTag.c_str(), Src.c_str());
 			   Version.c_str(), RelTag.c_str(), Src.c_str());
 
 
 		  if (Last != 0 || VerTag.empty() == true)
 		  if (Last != 0 || VerTag.empty() == true)

+ 12 - 10
test/integration/framework

@@ -849,31 +849,33 @@ Description-en: $DESCRIPTION
 }
 }
 
 
 insertsource() {
 insertsource() {
-	local RELEASE="$1"
+	local RELEASES="$1"
 	local NAME="$2"
 	local NAME="$2"
 	local ARCH="$3"
 	local ARCH="$3"
 	local VERSION="$4"
 	local VERSION="$4"
 	local DEPENDENCIES="$5"
 	local DEPENDENCIES="$5"
-        local BINARY="${6:-$NAME}"
+	local BINARY="${6:-$NAME}"
 	local ARCHS=""
 	local ARCHS=""
-	local SPATH="aptarchive/dists/${RELEASE}/main/source"
-	mkdir -p $SPATH
-	local FILE="${SPATH}/Sources"
-	local DSCFILE="${NAME}_${VERSION}.dsc"
-	local TARFILE="${NAME}_${VERSION}.tar.gz"
-	echo "Package: $NAME
+	for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
+		local SPATH="aptarchive/dists/${RELEASE}/main/source"
+		mkdir -p $SPATH
+		local FILE="${SPATH}/Sources"
+		local DSCFILE="${NAME}_${VERSION}.dsc"
+		local TARFILE="${NAME}_${VERSION}.tar.gz"
+		echo "Package: $NAME
 Binary: $BINARY
 Binary: $BINARY
 Version: $VERSION
 Version: $VERSION
 Maintainer: Joe Sixpack <joe@example.org>
 Maintainer: Joe Sixpack <joe@example.org>
 Architecture: $ARCH" >> $FILE
 Architecture: $ARCH" >> $FILE
-	test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
-	echo "Files:
+		test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
+		echo "Files:
  $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
  $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
 Checksums-Sha256:
 Checksums-Sha256:
  $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
  $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
 " >> "$FILE"
 " >> "$FILE"
+	done
 }
 }
 
 
 insertinstalledpackage() {
 insertinstalledpackage() {

+ 2 - 2
test/integration/test-apt-get-source

@@ -16,8 +16,8 @@ insertpackage 'unstable' 'foo' 'all' '2.0'
 insertsource 'unstable' 'foo' 'all' '2.0'
 insertsource 'unstable' 'foo' 'all' '2.0'
 
 
 # binary packages with Source-field
 # binary packages with Source-field
-insertpackage 'unstable' 'bin' 'i386' '3-2+b1' 'Source: bin (3-2)'
-insertsource 'unstable' 'bin' 'any' '3-2'
+insertpackage 'unstable,testing' 'bin' 'i386' '3-2+b1' 'Source: bin (3-2)'
+insertsource 'unstable,testing' 'bin' 'any' '3-2'
 insertpackage 'stable' 'bin' 'i386' '2-2+b1' 'Source: bin-backport (2-2)'
 insertpackage 'stable' 'bin' 'i386' '2-2+b1' 'Source: bin-backport (2-2)'
 insertsource 'stable' 'bin-backport' 'any' '2-2'
 insertsource 'stable' 'bin-backport' 'any' '2-2'