From 019dfaedcc169837f88cc0b971fd8897828d93bf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Dec 2013 07:58:37 +0100 Subject: add test, deal with InRelease --- test/integration/test-apt-get-source | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 test/integration/test-apt-get-source (limited to 'test/integration') diff --git a/test/integration/test-apt-get-source b/test/integration/test-apt-get-source new file mode 100755 index 000000000..d2b8deafd --- /dev/null +++ b/test/integration/test-apt-get-source @@ -0,0 +1,45 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture "i386" + +# we need to insert a package into "unstable" so that a Release file is +# create for the test +insertpackage 'wheezy' 'unreleated-package' 'all' '1.0' + +# a "normal" package with source and binary +insertpackage 'unstable' 'foo' 'all' '2.0' +insertsource 'unstable' 'foo' 'all' '2.0' + +insertpackage 'stable' 'foo' 'all' '1.0' +insertsource 'stable' 'foo' 'all' '1.0' + +# this package exists only as source +insertsource 'wheezy' 'foo' 'all' '0.1' + +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 + +# select by release +testequal "Selectied version '1.0' (stable) for foo +'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 + +# 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 + +# select by release with no binary package (Bug#731102) +testequal "Selectied version '0.1' (wheezy) for foo +'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 + -- cgit v1.2.3-70-g09d2 From 4652a9eee39df1cefa49ab177c0cfc50b9aad567 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Dec 2013 08:41:23 +0100 Subject: further refactor, extract GetReleaseForSourceRecord() out of FindSrc(), write out the selection notice to c1out to be consistent with the rest of the source --- cmdline/apt-get.cc | 85 ++++++++++++++++++------------------ test/integration/test-apt-get-source | 26 +++++++---- 2 files changed, 60 insertions(+), 51 deletions(-) (limited to 'test/integration') 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 *Indexes = (*S)->GetIndexFiles(); + for (vector::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 *Indexes = (*S)->GetIndexFiles(); - for (vector::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 -- cgit v1.2.3-70-g09d2 From c6b83f9c68aafa3f2bd1b695a6beb724d7520bc5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Dec 2013 16:26:57 +0100 Subject: add test for aptget source for unavailable package --- test/integration/test-apt-get-source | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/integration') diff --git a/test/integration/test-apt-get-source b/test/integration/test-apt-get-source index 0f9e29c80..5bef781f1 100755 --- a/test/integration/test-apt-get-source +++ b/test/integration/test-apt-get-source @@ -53,3 +53,8 @@ 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 -q --print-uris foo/wheezy +# unavailable one +testequal "$HEADER +E: Ignore unavailable version '9.9-not-there' of package 'foo' +E: Unable to find a source package for foo" aptget source -q --print-uris foo=9.9-not-there + -- cgit v1.2.3-70-g09d2