diff options
| author | Julian Andres Klode <jak@debian.org> | 2024-04-29 14:33:41 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2024-04-29 14:33:41 +0000 |
| commit | 4a76c77d1cd3f07c01d5908cca539ed90d1793d3 (patch) | |
| tree | 66101d7488a186467488559f17cdd3768e5aadc4 | |
| parent | c98bcdf00e5366fec101dd17094d36be21872a02 (diff) | |
| parent | 84881c1914ca30435ff478b4138cd7559c35c8d1 (diff) | |
Merge branch 'src-specifier' into 'main'
showsrc, source, build-dep: Support src:name
See merge request apt-team/apt!346
| -rw-r--r-- | apt-private/private-show.cc | 14 | ||||
| -rw-r--r-- | apt-private/private-source.cc | 8 | ||||
| -rwxr-xr-x | test/integration/test-apt-cache-showsrc | 6 | ||||
| -rwxr-xr-x | test/integration/test-apt-get-source-only | 114 |
4 files changed, 138 insertions, 4 deletions
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 4ae043071..ceef6707e 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -446,14 +446,22 @@ bool ShowSrcPackage(CommandLine &CmdL) /*{{{*/ std::set<std::string> seen; for (const char **I = CmdL.FileList + 1; *I != 0; I++) { + const char *pkgname = *I; SrcRecs.Restart(); pkgSrcRecords::Parser *Parse; bool found_this = false; - while ((Parse = SrcRecs.Find(*I,false)) != 0) { + bool only_source = _config->FindB("APT::Cache::Only-Source", false); + if (APT::String::Startswith(pkgname, "src:")) + { + only_source = true; + pkgname += 4; + } + while ((Parse = SrcRecs.Find(pkgname, false)) != 0) + { // SrcRecs.Find() will find both binary and source names - if (_config->FindB("APT::Cache::Only-Source", false) == true) - if (Parse->Package() != *I) + if (only_source) + if (Parse->Package() != pkgname) continue; std::string sha1str = Sha1FromString(Parse->AsStr()); if (std::find(seen.begin(), seen.end(), sha1str) == seen.end()) diff --git a/apt-private/private-source.cc b/apt-private/private-source.cc index 9b9409c80..6280b9fff 100644 --- a/apt-private/private-source.cc +++ b/apt-private/private-source.cc @@ -77,7 +77,14 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name, std::string ArchTag = ""; std::string RelTag = _config->Find("APT::Default-Release"); std::string TmpSrc = Name; + bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source"); + // Check if we should look by source package + if (APT::String::Startswith(TmpSrc, "src:")) + { + MatchSrcOnly = true; + TmpSrc = TmpSrc.substr(4); + } // extract release size_t found = TmpSrc.find_last_of("/"); if (found != std::string::npos) @@ -103,7 +110,6 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name, /* Lookup the version of the package we would install if we were to install a version and determine the source package name, then look in the archive for a source package of the same name. */ - bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source"); pkgCache::PkgIterator Pkg; if (ArchTag != "") Pkg = Cache.GetPkgCache()->FindPkg(TmpSrc, ArchTag); diff --git a/test/integration/test-apt-cache-showsrc b/test/integration/test-apt-cache-showsrc index d3f61d972..0f0e21d35 100755 --- a/test/integration/test-apt-cache-showsrc +++ b/test/integration/test-apt-cache-showsrc @@ -29,3 +29,9 @@ testsuccess grep "Package: unrelated" output.txt aptcache showsrc --only-source foo > output.txt testsuccess grep "Package: foo" output.txt testfailure grep "Package: unrelated" output.txt + +# by default apt-cache showsrc will look into "binary" and "source" names +# and show all matches +aptcache showsrc src:foo > output.txt +testsuccess grep "Package: foo" output.txt +testfailure grep "Package: unrelated" output.txt diff --git a/test/integration/test-apt-get-source-only b/test/integration/test-apt-get-source-only new file mode 100755 index 000000000..93d82844c --- /dev/null +++ b/test/integration/test-apt-get-source-only @@ -0,0 +1,114 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" + +setupenvironment +configarchitecture "amd64" + + +# not-foo builds foo, but foo builds not-foo +insertpackage 'stable' 'foo' 'amd64' '1.0' 'Source: not-foo' +insertsource 'stable' 'not-foo' 'amd64' '1.0' 'Build-Depends: not-foo-bd' 'foo' + +insertpackage 'stable' 'not-foo' 'amd64' '1.0' 'Source: foo' +insertsource 'stable' 'foo' 'amd64' '1.0' 'Build-Depends: foo-bd' 'not-foo' + +insertinstalledpackage 'build-essential' 'amd64' '1.0' + +setupaptarchive + +APTARCHIVE=$(readlink -f ./aptarchive) + +HEADER='Reading package lists...' +DOWNLOADFOO="Need to get 0 B/25 B of source archives. +'file:${APTARCHIVE}/foo_1.0.dsc' foo_1.0.dsc 11 SHA256:ed7c25c832596339bee13e4e7c45cf49f869b60d2bf57252f18191d75866c2a7 +'file:${APTARCHIVE}/foo_1.0.tar.gz' foo_1.0.tar.gz 14 SHA256:f3da8c6ebc62c8ef2dae439a498dddcdacc1a07f45ff67ad12f44b6e2353c239" +DOWNLOADNOTFOO="Need to get 0 B/33 B of source archives. +'file:${APTARCHIVE}/not-foo_1.0.dsc' not-foo_1.0.dsc 15 SHA256:db578a571c87d2555e90245732042845be4f481755f5b2f5786ac7a26bde9f4f +'file:${APTARCHIVE}/not-foo_1.0.tar.gz' not-foo_1.0.tar.gz 18 SHA256:8701846f1cba0ca81c552ac0ec93e2a89ae113cf2872b9cd51b29b4a9ff6b122" + +BUILDDEPFOO="Reading package lists... +Building dependency tree... +Some packages could not be installed. This may mean that you have +requested an impossible situation or if you are using the unstable +distribution that some required packages have not yet been created +or been moved out of Incoming. +The following information may help to resolve the situation: + +The following packages have unmet dependencies: + builddeps:foo : Depends: foo-bd but it is not installable +E: Unable to correct problems, you have held broken packages." + +BUILDDEPNOTFOO="Reading package lists... +Building dependency tree... +Some packages could not be installed. This may mean that you have +requested an impossible situation or if you are using the unstable +distribution that some required packages have not yet been created +or been moved out of Incoming. +The following information may help to resolve the situation: + +The following packages have unmet dependencies: + builddeps:not-foo : Depends: not-foo-bd but it is not installable +E: Unable to correct problems, you have held broken packages." + +testsuccessequal "$HEADER +Picking 'not-foo' as source package instead of 'foo' +$DOWNLOADNOTFOO" aptget source -q --print-uris foo + +testsuccessequal "$HEADER +Picking 'not-foo' as source package instead of 'foo' +$DOWNLOADNOTFOO" aptget source -q --print-uris foo:amd64 + +testsuccessequal "$HEADER +$DOWNLOADNOTFOO" aptget source -q --print-uris --only-source not-foo + +testsuccessequal "$HEADER +$DOWNLOADNOTFOO" aptget source -q --print-uris src:not-foo + +testsuccessequal "$HEADER +Picking 'foo' as source package instead of 'not-foo' +$DOWNLOADFOO" aptget source -q --print-uris not-foo + +testsuccessequal "$HEADER +Picking 'foo' as source package instead of 'not-foo' +$DOWNLOADFOO" aptget source -q --print-uris not-foo:amd64 + +testsuccessequal "$HEADER +$DOWNLOADFOO" aptget source -q --print-uris --only-source foo + +testsuccessequal "$HEADER +$DOWNLOADFOO" aptget source -q --print-uris src:foo + +# Same dance with build-dep +testequal "$HEADER +Picking 'not-foo' as source package instead of 'foo' +$BUILDDEPNOTFOO" aptget build-dep -q -s foo + +testequal "$HEADER +Picking 'not-foo' as source package instead of 'foo' +$BUILDDEPNOTFOO" aptget build-dep -q -s foo:amd64 + +testequal "$HEADER +$BUILDDEPNOTFOO" aptget build-dep -q -s --only-source not-foo + +testequal "$HEADER +$BUILDDEPNOTFOO" aptget build-dep -q -s src:not-foo + +testequal "$HEADER +Picking 'foo' as source package instead of 'not-foo' +$BUILDDEPFOO" aptget build-dep -q -s not-foo + +testequal "$HEADER +Picking 'foo' as source package instead of 'not-foo' +$BUILDDEPFOO" aptget build-dep -q -s not-foo:amd64 + +testequal "$HEADER +$BUILDDEPFOO" aptget build-dep -q -s --only-source foo + +testequal "$HEADER +$BUILDDEPFOO" aptget build-dep -q -s src:foo + + + |
