]> git.saurik.com Git - apt.git/commitdiff
allow explicit dis/enable of IndexTargets in sources options
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 27 Aug 2015 08:41:19 +0000 (10:41 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Thu, 27 Aug 2015 09:27:45 +0000 (11:27 +0200)
While Target{,-Add,-Remove} is available for configuring IndexTargets
already, allow Targets to be mentioned explicitely as yes/no options as
well, so that the Target 'Contents' can be disabled via 'Contents: no'
as well as 'Target-Remove: Contents'.

apt-pkg/deb/debmetaindex.cc
doc/sources.list.5.xml
test/integration/framework
test/integration/test-sourceslist-target-plusminus-options [new file with mode: 0755]

index 8e05127594da85a638d4d5b0e48f2353d50c3c6f..69e41a6f46ea0572c8c2765c786323414a229ed3 100644 (file)
@@ -715,10 +715,25 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type             /*{{{*/
         List.push_back(Deb);
       }
 
+      std::vector<std::string> const alltargets = _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true);
+      std::vector<std::string> mytargets = parsePlusMinusOptions("target", Options, alltargets);
+      if (mytargets.empty() == false)
+        for (auto const &target : alltargets)
+        {
+           std::map<std::string, std::string>::const_iterator const opt = Options.find(target);
+           if (opt == Options.end())
+              continue;
+           auto const tarItr = std::find(mytargets.begin(), mytargets.end(), target);
+           bool const optValue = StringToBool(opt->second);
+           if (optValue == true && tarItr == mytargets.end())
+              mytargets.push_back(target);
+           else if (optValue == false && tarItr != mytargets.end())
+              mytargets.erase(std::remove(mytargets.begin(), mytargets.end(), target), mytargets.end());
+        }
       Deb->AddComponent(
            IsSrc,
            Section,
-           parsePlusMinusOptions("target", Options, _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true)),
+           mytargets,
            parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()),
            parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true))
            );
index 77458d8fe5898fecb929d9250cdbaaa9b12be606..4eb3c0ba0c9cb528d6b98ae3552602cf831f1625 100644 (file)
@@ -222,6 +222,9 @@ deb-src [ option1=value1 option2=value2 ] uri suite [component1] [component2] [.
                which download targets apt will try to acquire from this
                source. If not specified, the default set is defined by the
                <option>Acquire::IndexTargets</option> configuration scope.
+               Aditionally, specific targets can be enabled or disabled by
+               using the identifier as field name instead of using this
+               multivalue option.
          </para></listitem>
        </itemizedlist>
 
index c046507e436348c56df8506d85c3cf2af4b0701a..03f1be114d1e83dba0b397ad867f5e80dcec4162 100644 (file)
@@ -1196,9 +1196,16 @@ checkdiff() {
 }
 
 testfileequal() {
+       local MSG='Test for correctness of file'
+       if [ "$1" = '--nomsg' ]; then
+               MSG=''
+               shift
+       fi
        local FILE="$1"
        shift
-       msgtest "Test for correctness of file" "$FILE"
+       if [ -n "$MSG" ]; then
+               msgtest "$MSG" "$FILE"
+       fi
        if [ -z "$*" ]; then
                echo -n "" | checkdiff - $FILE && msgpass || msgfail
        else
diff --git a/test/integration/test-sourceslist-target-plusminus-options b/test/integration/test-sourceslist-target-plusminus-options
new file mode 100755 (executable)
index 0000000..00d9085
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64'
+
+testtargets() {
+       msgtest 'Test acquired targets for' "$1"
+       shift
+       while [ -n "$1" ]; do
+               echo "$1"
+               shift
+       done | sort -u > expectedtargets.lst
+       aptget indextargets --no-release-info --format='$(CREATED_BY)' | sort -u > gottargets.lst
+       testfileequal --nomsg ./expectedtargets.lst "$(cat ./gottargets.lst)"
+}
+
+echo 'deb http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'default' 'Packages' 'Translations'
+
+cat > rootdir/etc/apt/apt.conf.d/content-target.conf <<EOF
+Acquire::IndexTargets::deb::Contents {
+       MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
+       ShortDescription "Contents";
+       Description "\$(RELEASE)/\$(COMPONENT) \$(ARCHITECTURE) Contents";
+};
+EOF
+testtargets 'default + Contents' 'Packages' 'Translations' 'Contents'
+
+echo 'deb [target=Packages] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'force Packages target' 'Packages'
+
+echo 'deb [target=Contents] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'force Contents target' 'Contents'
+
+echo 'deb [target=Translations,Contents] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'force two targets' 'Contents' 'Translations'
+
+echo 'deb [target+=Translations,Contents] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'add existing' 'Packages' 'Contents' 'Translations'
+
+echo 'deb [target+=AppStream] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'add non-existing' 'Packages' 'Contents' 'Translations'
+
+echo 'deb [target-=Translations,Contents] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'remove existing' 'Packages'
+
+echo 'deb [target-=AppStream] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'remove non-existing' 'Packages' 'Contents' 'Translations'
+
+echo 'deb [AppStream=yes] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'activate non-existing' 'Packages' 'Contents' 'Translations'
+
+echo 'deb [AppStream=no] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'deactivate non-existing' 'Packages' 'Contents' 'Translations'
+
+echo 'deb [Contents=yes] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'activate existing' 'Packages' 'Contents' 'Translations'
+
+echo 'deb [Contents=no] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'deactivate existing' 'Packages' 'Translations'
+
+echo 'deb [target=Packages Contents=yes] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list
+testtargets 'explicit + activate' 'Packages' 'Contents'