summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-12-04 08:41:23 +0100
committerMichael Vogt <mvo@debian.org>2013-12-04 08:41:23 +0100
commit4652a9eee39df1cefa49ab177c0cfc50b9aad567 (patch)
tree9adc962b25b5106088c686a9f279301041b4b746
parent7b33ae1070f3ecff0f20745db7edeead8dfc3a05 (diff)
further refactor, extract GetReleaseForSourceRecord() out of FindSrc(), write out the selection notice to c1out to be consistent with the rest of the source
-rw-r--r--cmdline/apt-get.cc85
-rwxr-xr-xtest/integration/test-apt-get-source26
2 files changed, 60 insertions, 51 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index 3205fd90a..15742c8e5 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -152,6 +152,29 @@ std::string MetaIndexFileName(metaIndex *metaindex)
URItoFileName(r->MetaIndexURI("Release"));
}
+std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
+ pkgSrcRecords::Parser *Parse)
+{
+ // try to find release
+ const pkgIndexFile& SI = Parse->Index();
+ for (pkgSourceList::const_iterator S = SrcList->begin();
+ S != SrcList->end(); ++S)
+ {
+ vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
+ for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
+ IF != Indexes->end(); ++IF)
+ {
+ if (&SI == (*IF))
+ {
+ std::string path = MetaIndexFileName(*S);
+ indexRecords records;
+ records.Load(path);
+ return records.GetSuite();
+ }
+ }
+ }
+ return "";
+}
// FindSrc - Find a source record /*{{{*/
@@ -162,7 +185,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
CacheFile &CacheFile)
{
string VerTag;
- string DefRel = _config->Find("APT::Default-Release");
+ string RelTag = _config->Find("APT::Default-Release");
string TmpSrc = Name;
pkgDepCache *Cache = CacheFile.GetDepCache();
@@ -170,7 +193,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
const size_t found = TmpSrc.find_last_of("/=");
if (found != string::npos) {
if (TmpSrc[found] == '/')
- DefRel = TmpSrc.substr(found+1);
+ RelTag = TmpSrc.substr(found+1);
else
VerTag = TmpSrc.substr(found+1);
TmpSrc = TmpSrc.substr(0,found);
@@ -183,7 +206,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
const pkgCache::PkgIterator Pkg = Cache->FindPkg(TmpSrc);
if (MatchSrcOnly == false && Pkg.end() == false)
{
- if(VerTag.empty() == false || DefRel.empty() == false)
+ if(VerTag.empty() == false || RelTag.empty() == false)
{
bool fuzzy = false;
// we have a default release, try to locate the pkg. we do it like
@@ -223,8 +246,8 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
// or we match against a release
if(VerTag.empty() == false ||
- (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) ||
- (VF.File().Codename() != 0 && VF.File().Codename() == DefRel))
+ (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
+ (VF.File().Codename() != 0 && VF.File().Codename() == RelTag))
{
pkgRecords::Parser &Parse = Recs.Lookup(VF);
Src = Parse.SourcePkg();
@@ -242,23 +265,13 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
if (Src.empty() == false)
break;
}
-#if 0
- if (Src.empty() == true)
- {
- // Sources files have no codename information
- if (VerTag.empty() == true && DefRel.empty() == false)
- {
- _error->Warning(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str());
- return 0;
- }
- }
-#endif
}
if (Src.empty() == true)
{
// if we don't have found a fitting package yet so we will
// choose a good candidate and proceed with that.
// Maybe we will find a source later on with the right VerTag
+ // or RelTag
pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
if (Ver.end() == false)
{
@@ -271,7 +284,9 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
}
if (Src.empty() == true)
+ {
Src = TmpSrc;
+ }
else
{
/* if we have a source pkg name, make sure to only search
@@ -301,36 +316,20 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
{
const string Ver = Parse->Version();
+ const string Rel = GetReleaseForSourceRecord(SrcList, Parse);
- // try to find release
- const pkgIndexFile& SI = Parse->Index();
-
- for (pkgSourceList::const_iterator S = SrcList->begin();
- S != SrcList->end(); ++S)
+ if (RelTag != "" && Rel == RelTag)
{
- vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
- for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
- IF != Indexes->end(); ++IF)
- {
- if (&SI == (*IF))
- {
- std::string path = MetaIndexFileName(*S);
- indexRecords records;
- records.Load(path);
- if (records.GetSuite() == DefRel)
- {
- ioprintf(clog, "Selectied version '%s' (%s) for %s\n",
- Ver.c_str(), DefRel.c_str(), Src.c_str());
- Last = Parse;
- Offset = Parse->Offset();
- Version = Ver;
- FoundRel = DefRel;
- break;
- }
- }
- }
+ ioprintf(c1out, "Selectied version '%s' (%s) for %s\n",
+ Ver.c_str(), RelTag.c_str(), Src.c_str());
+ Last = Parse;
+ Offset = Parse->Offset();
+ Version = Ver;
+ FoundRel = RelTag;
+ break;
}
- if (DefRel.empty() == false && (DefRel == FoundRel))
+
+ if (RelTag.empty() == false && (RelTag == FoundRel))
break;
// Ignore all versions which doesn't fit
diff --git a/test/integration/test-apt-get-source b/test/integration/test-apt-get-source
index d2b8deafd..0f9e29c80 100755
--- a/test/integration/test-apt-get-source
+++ b/test/integration/test-apt-get-source
@@ -26,20 +26,30 @@ setupaptarchive
APTARCHIVE=$(readlink -f ./aptarchive)
# normal operation gets highest version number
-testequal "'file://${APTARCHIVE}/foo_2.0.dsc' foo_2.0.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e
-'file://${APTARCHIVE}/foo_2.0.tar.gz' foo_2.0.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -qq --print-uris foo
+HEADER="Reading package lists...
+Building dependency tree..."
+testequal "$HEADER
+Need to get 0 B of source archives.
+'file://${APTARCHIVE}/foo_2.0.dsc' foo_2.0.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e
+'file://${APTARCHIVE}/foo_2.0.tar.gz' foo_2.0.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -q --print-uris foo
# select by release
-testequal "Selectied version '1.0' (stable) for foo
+testequal "$HEADER
+Selectied version '1.0' (stable) for foo
+Need to get 0 B of source archives.
'file://${APTARCHIVE}/foo_1.0.dsc' foo_1.0.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e
-'file://${APTARCHIVE}/foo_1.0.tar.gz' foo_1.0.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -qq --print-uris foo/stable
+'file://${APTARCHIVE}/foo_1.0.tar.gz' foo_1.0.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -q --print-uris foo/stable
# select by version
-testequal "'file://${APTARCHIVE}/foo_1.0.dsc' foo_1.0.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e
-'file://${APTARCHIVE}/foo_1.0.tar.gz' foo_1.0.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -qq --print-uris foo=1.0
+testequal "$HEADER
+Need to get 0 B of source archives.
+'file://${APTARCHIVE}/foo_1.0.dsc' foo_1.0.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e
+'file://${APTARCHIVE}/foo_1.0.tar.gz' foo_1.0.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -q --print-uris foo=1.0
# select by release with no binary package (Bug#731102)
-testequal "Selectied version '0.1' (wheezy) for foo
+testequal "$HEADER
+Selectied version '0.1' (wheezy) for foo
+Need to get 0 B of source archives.
'file://${APTARCHIVE}/foo_0.1.dsc' foo_0.1.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e
-'file://${APTARCHIVE}/foo_0.1.tar.gz' foo_0.1.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -qq --print-uris foo/wheezy
+'file://${APTARCHIVE}/foo_0.1.tar.gz' foo_0.1.tar.gz 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -q --print-uris foo/wheezy