]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/policy.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 16 Jul 2011 14:48:03 +0000 (16:48 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 16 Jul 2011 14:48:03 +0000 (16:48 +0200)
  - emit an error on unknown APT::Default-Release value (Closes: #407511)

apt-pkg/policy.cc
debian/changelog
test/integration/framework
test/integration/test-bug-407511-fail-invalid-default-release [new file with mode: 0755]

index bd213e0ce59f0a47b8a0fba056652efe7b381ebb..c5028d822aa6bbbb22b5fd8a618dbe33b8ff788c 100644 (file)
@@ -56,8 +56,22 @@ pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner)
    // The config file has a master override.
    string DefRel = _config->Find("APT::Default-Release");
    if (DefRel.empty() == false)
-      CreatePin(pkgVersionMatch::Release,"",DefRel,990);
-      
+   {
+      bool found = false;
+      // FIXME: make ExpressionMatches static to use it here easily
+      pkgVersionMatch vm("", pkgVersionMatch::None);
+      for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
+      {
+        if ((F->Archive != 0 && vm.ExpressionMatches(DefRel, F.Archive()) == true) ||
+            (F->Codename != 0 && vm.ExpressionMatches(DefRel, F.Codename()) == true) ||
+            (F->Version != 0 && vm.ExpressionMatches(DefRel, F.Version()) == true))
+           found = true;
+      }
+      if (found == false)
+        _error->Error(_("The value '%s' is invalid for APT::Default-Release as such a release is not available in the sources"), DefRel.c_str());
+      else
+        CreatePin(pkgVersionMatch::Release,"",DefRel,990);
+   }
    InitDefaults();
 }
                                                                        /*}}}*/
index a834bca9191fb623e5c6d8fee6806dd1687a92dd..607f7c64a05f2bce6aa1f94b18ea0c6355c5d67c 100644 (file)
@@ -28,8 +28,10 @@ apt (0.8.15.3) UNRELEASED; urgency=low
     - remove /etc/apt/secring.gpg if it is an empty file
   * doc/apt-cache.8.xml:
     - apply madison typofix from John Feuerstein, thanks! (Closes: #633455)
+  * apt-pkg/policy.cc:
+    - emit an error on unknown APT::Default-Release value (Closes: #407511)
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Sat, 16 Jul 2011 14:55:03 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com>  Sat, 16 Jul 2011 16:43:37 +0200
 
 apt (0.8.15.2) unstable; urgency=high
 
index 96cdb5f5e31b9f01368646b5cdb0fdf5a17bcc7a..702e352a309d071b5ddc4dd5c05cfefe00c31eda 100644 (file)
@@ -481,6 +481,10 @@ buildaptarchivefromfiles() {
        generatereleasefiles
 }
 
+# can be overridden by testcases for their pleasure
+getcodenamefromsuite() { echo -n "$1"; }
+getreleaseversionfromsuite() { true; }
+
 generatereleasefiles() {
        msgninfo "\tGenerate Release files… "
        local DATE="${1:-now}"
@@ -489,9 +493,22 @@ generatereleasefiles() {
                        aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index
                done
                for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
-                       local CODENAME="$(echo "$dir" | cut -d'/' -f 4)"
-                       aptftparchive -qq release $dir -o APT::FTPArchive::Release::Suite="${CODENAME}" -o APT::FTPArchive::Release::Codename="${CODENAME}" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
-                       if [ "$CODENAME" = "experimental" -o "$CODENAME" = "experimental2" ]; then
+                       local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
+                       local CODENAME="$(getcodenamefromsuite $SUITE)"
+                       local VERSION="$(getreleaseversionfromsuite $SUITE)"
+                       if [ -z "$VERSION" ]; then
+                               aptftparchive -qq release $dir \
+                                       -o APT::FTPArchive::Release::Suite="${SUITE}" \
+                                       -o APT::FTPArchive::Release::Codename="${CODENAME}" \
+                                               | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
+                       else
+                               aptftparchive -qq release $dir \
+                                       -o APT::FTPArchive::Release::Suite="${SUITE}" \
+                                       -o APT::FTPArchive::Release::Codename="${CODENAME}" \
+                                       -o APT::FTPArchive::Release::Version="${VERSION}" \
+                                               | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
+                       fi
+                       if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
                                sed -i '/^Date: / a\
 NotAutomatic: yes' $dir/Release
                        fi
diff --git a/test/integration/test-bug-407511-fail-invalid-default-release b/test/integration/test-bug-407511-fail-invalid-default-release
new file mode 100755 (executable)
index 0000000..d0a73af
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+insertpackage 'unstable' 'cool' 'all' '1.0-1'
+
+getcodenamefromsuite() {
+       if [ "$SUITE" = 'unstable' ]; then
+               echo -n 'sid'
+       else
+               echo -n "$SUITE"
+       fi
+}
+getreleaseversionfromsuite() {
+       if [ "$SUITE" = 'unstable' ]; then
+               echo -n '42.0'
+       else
+               echo -n '0.8.15'
+       fi
+}
+
+setupaptarchive
+
+passdist() {
+       msgtest "Test that target-release is accepted" $1
+       aptget dist-upgrade -t $1 -qq && msgpass || msgfail
+}
+
+faildist() {
+       msgtest "Test that target-release is refused" $1
+       aptget dist-upgrade -t $1 -qq 2> /dev/null && msgfail || msgpass
+}
+
+passdist unstable
+passdist sid
+faildist sidd
+faildist stable
+passdist 42.0
+passdist 42.*
+passdist 42*
+passdist 4*.0
+faildist 21.0
+faildist 21*