]> git.saurik.com Git - apt.git/commitdiff
Replace --force-yes by various options starting with --allow
authorJulian Andres Klode <jak@debian.org>
Fri, 14 Aug 2015 09:49:45 +0000 (11:49 +0200)
committerJulian Andres Klode <jak@debian.org>
Fri, 14 Aug 2015 10:38:18 +0000 (12:38 +0200)
This enables more fine grained control over such exceptions.

apt-private/private-cmndline.cc
apt-private/private-download.cc
apt-private/private-install.cc
doc/apt-get.8.xml
test/integration/test-allow [new file with mode: 0755]
test/integration/test-apt-get-update-unauth-warning
test/integration/test-apt-never-markauto-sections
test/integration/test-apt-update-nofallback
test/integration/test-apt-update-rollback
test/integration/test-bug-712116-dpkg-pre-install-pkgs-hook-multiarch
test/integration/test-releasefile-verification

index fa84168242680d30d7270d4e8465bcbb2c8d7b4f..487349c8c206e9e2898e48008c4bef102d7286c8 100644 (file)
@@ -202,6 +202,9 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const
    addArg(0,"ignore-hold","APT::Ignore-Hold",0);
    addArg(0,"upgrade","APT::Get::upgrade",0);
    addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0);
+   addArg(0,"allow-change-held-packages","APT::Get::allow-change-held-packages",CommandLine::Boolean);
+   addArg(0,"allow-remove-essential","APT::Get::allow-remove-essential",CommandLine::Boolean);
+   addArg(0,"allow-downgrades","APT::Get::allow-downgrades",CommandLine::Boolean);
    addArg(0,"force-yes","APT::Get::force-yes",0);
    addArg(0,"print-uris","APT::Get::Print-URIs",0);
    addArg(0,"trivial-only","APT::Get::Trivial-Only",0);
index 09914618760ef9311742efa0de46b18666f5aadb..18a9b1fbce23429b63bf8f956c868d6e8d7c3cfe 100644 (file)
@@ -114,10 +114,12 @@ bool AuthPrompt(std::vector<std::string> const &UntrustedList, bool const Prompt
 
       return true;
    }
-   else if (_config->FindB("APT::Get::Force-Yes",false) == true)
+   else if (_config->FindB("APT::Get::Force-Yes",false) == true) {
+      _error->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead."));
       return true;
+   }
 
-   return _error->Error(_("There are problems and -y was used without --force-yes"));
+   return _error->Error(_("There were unauthenticated packages and -y was used without --allow-unauthenticated"));
 }
                                                                        /*}}}*/
 bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure)/*{{{*/
index d2b4bed51ee927541e0b5acac833076c8850880b..96e33f7dead319d29d393ab617b8d4283357afe9 100644 (file)
@@ -58,7 +58,8 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       }
    }
    
-   bool Fail = false;
+   bool Hold = false;
+   bool Downgrade = false;
    bool Essential = false;
    
    // Show all the various warning indicators
@@ -66,13 +67,17 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
    ShowNew(c1out,Cache);
    if (ShwKept == true)
       ShowKept(c1out,Cache);
-   Fail |= !ShowHold(c1out,Cache);
+   Hold = !ShowHold(c1out,Cache);
    if (_config->FindB("APT::Get::Show-Upgraded",true) == true)
       ShowUpgraded(c1out,Cache);
-   Fail |= !ShowDowngraded(c1out,Cache);
+   Downgrade = !ShowDowngraded(c1out,Cache);
+
    if (_config->FindB("APT::Get::Download-Only",false) == false)
         Essential = !ShowEssential(c1out,Cache);
-   Fail |= Essential;
+
+   // All kinds of failures
+   bool Fail = (Essential || Downgrade || Hold);
+
    Stats(c1out,Cache);
 
    // Sanity check
@@ -89,7 +94,25 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
    // No remove flag
    if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false)
       return _error->Error(_("Packages need to be removed but remove is disabled."));
-       
+
+   // Fail safe check
+   if (_config->FindI("quiet",0) >= 2 ||
+       _config->FindB("APT::Get::Assume-Yes",false) == true)
+   {
+      if (_config->FindB("APT::Get::Force-Yes",false) == true) {
+        _error->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead."));
+      }
+
+      if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false) {
+        if (Essential == true && _config->FindB("APT::Get::allow-remove-essential", false) == false)
+           return _error->Error(_("Essential packages were removed and -y was used without --allow-remove-essential."));
+        if (Downgrade == true && _config->FindB("APT::Get::allow-downgrades", false) == false)
+           return _error->Error(_("Packages were downgraded and -y was used without --allow-downgrades."));
+        if (Hold == true && _config->FindB("APT::Get::allow-change-held-packages", false) == false)
+           return _error->Error(_("Held packages were changed and -y was used without --allow-change-held-packages."));
+      }
+   }
+
    // Run the simulator ..
    if (_config->FindB("APT::Get::Simulate") == true)
    {
@@ -173,15 +196,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
    if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false)
       return false;
 
-   // Fail safe check
-   if (_config->FindI("quiet",0) >= 2 ||
-       _config->FindB("APT::Get::Assume-Yes",false) == true)
-   {
-      if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false)
-        return _error->Error(_("There are problems and -y was used without --force-yes"));
-   }         
-
-   if (Essential == true && Safety == true)
+   if (Essential == true && Safety == true && _config->FindB("APT::Get::allow-remove-essential", false) == false)
    {
       if (_config->FindB("APT::Get::Trivial-Only",false) == true)
         return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
index 81a9036c452a93b7cfc17c2ebccb0ba133aa062e..76a53aec298f387712711904fa4c9cc90d4fc805 100644 (file)
      Configuration Item: <literal>APT::Get::Only-Upgrade</literal>.</para></listitem>
      </varlistentry>
 
+     <varlistentry><term><option>--allow-downgrades</option></term>
+     <listitem><para>This is a dangerous option that will cause apt to continue
+     without prompting if it is doing downgrades. It
+     should not be used except in very special situations. Using
+     it can potentially destroy your system!
+     Configuration Item: <literal>APT::Get::allow-downgrades</literal>. Introduced in APT 1.1.</para></listitem>
+     </varlistentry>
+
+     <varlistentry><term><option>--allow-remove-essential</option></term>
+     <listitem><para>Force yes; this is a dangerous option that will cause apt to continue
+     without prompting if it is removing essentials. It
+     should not be used except in very special situations. Using
+     it can potentially destroy your system!
+     Configuration Item: <literal>APT::Get::allow-remove-essential</literal>. Introduced in APT 1.1.</para></listitem>
+     </varlistentry>
+
+     <varlistentry><term><option>--allow-change-held-packages</option></term>
+     <listitem><para>Force yes; this is a dangerous option that will cause apt to continue
+     without prompting if it is changing held packages. It
+     should not be used except in very special situations. Using
+     it can potentially destroy your system!
+     Configuration Item: <literal>APT::Get::allow-change-held-packages</literal>. Introduced in APT 1.1.</para></listitem>
+     </varlistentry>
+
      <varlistentry><term><option>--force-yes</option></term>
      <listitem><para>Force yes; this is a dangerous option that will cause apt to continue 
      without prompting if it is doing something potentially harmful. It 
      should not be used except in very special situations. Using 
      <literal>force-yes</literal> can potentially destroy your system! 
-     Configuration Item: <literal>APT::Get::force-yes</literal>.</para></listitem>
+     Configuration Item: <literal>APT::Get::force-yes</literal>. This is deprecated and replaced by <option>--allow-downgrades</option>, <option>--allow-remove-essential</option>, <option>--allow-change-held-packages</option> in 1.1. </para></listitem>
      </varlistentry>
 
      <varlistentry><term><option>--print-uris</option></term>
diff --git a/test/integration/test-allow b/test/integration/test-allow
new file mode 100755 (executable)
index 0000000..3d773ee
--- /dev/null
@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# Test for --allow-remove-essential and friends replacing --force-yes
+#
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64'
+
+insertpackage 'unstable' 'downgrade' 'all' '1'
+insertinstalledpackage 'downgrade' 'all' '2'
+
+insertpackage 'unstable' 'hold' 'all' '2'
+insertinstalledpackage 'hold' 'all' '1'
+
+insertinstalledpackage 'essential' 'all' '1' 'Essential: yes'
+
+setupaptarchive
+
+testsuccess aptmark hold hold
+
+# Test --allow-remove--essential
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+  essential
+WARNING: The following essential packages will be removed.
+This should NOT be done unless you know exactly what you are doing!
+  essential
+0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
+E: Essential packages were removed and -y was used without --allow-remove-essential.' aptget remove essential -y -s
+
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+  essential
+WARNING: The following essential packages will be removed.
+This should NOT be done unless you know exactly what you are doing!
+  essential
+0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
+Remv essential [1]' aptget remove essential -y --allow-remove-essential -s
+
+# Test --allow-change-held-packages (should not influence dist-upgrade, but an install)
+
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+Calculating upgrade...
+The following packages have been kept back:
+  hold
+0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.' aptget dist-upgrade --allow-change-held-packages -s
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+The following held packages will be changed:
+  hold
+The following packages will be upgraded:
+  hold
+1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+E: Held packages were changed and -y was used without --allow-change-held-packages.' aptget install hold -y -s
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+The following held packages will be changed:
+  hold
+The following packages will be upgraded:
+  hold
+1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+E: Held packages were changed and -y was used without --allow-change-held-packages.' aptget install hold -y  -s
+
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+The following held packages will be changed:
+  hold
+The following packages will be upgraded:
+  hold
+1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+Inst hold [1] (2 unstable [all])
+Conf hold (2 unstable [all])' aptget install hold -y  -s --allow-change-held-packages
+
+# Test --allow-downgrades
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+The following packages will be DOWNGRADED:
+  downgrade
+0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 1 not upgraded.
+E: Packages were downgraded and -y was used without --allow-downgrades.' aptget install downgrade=1 -y -s
+
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+The following packages will be DOWNGRADED:
+  downgrade
+0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 1 not upgraded.
+Inst downgrade [2] (1 unstable [all])
+Conf downgrade (1 unstable [all])' aptget install downgrade=1 --allow-downgrades -y -s
index bc8e6d3eaaba801abac61b8eb01fa8920903cf7c..4c45f8f26e53dc65a6419d36df9e1f61dafe00a4 100755 (executable)
@@ -81,4 +81,4 @@ W: The repository 'file:$APTARCHIVE unstable Release' does not have a Release fi
 # ensure we can not install the package
 testfailureequal "WARNING: The following packages cannot be authenticated!
   foo
-E: There are problems and -y was used without --force-yes" aptget install -qq -y foo
+E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y foo
index a469b4c15af03240890521ed062f37892ce7328e..9f490a1bdd9386a75675b425fa506aa2917ba25e 100755 (executable)
@@ -65,7 +65,7 @@ testmarkedauto
 
 # test that installed/upgraded auto-pkgs are not set to manual
 
-testsuccess aptget install browser=41 -y --force-yes
+testsuccess aptget install browser=41 -y --allow-downgrades
 
 testmarkedmanual 'browser' 'dpkg' 'foreignpkg:i386' 'nosection'
 testmarkedauto
index 2f4ddc016bedbc276098bf251a01819987b3de51..6e9db2cae8e7e9d3e89c94d24b1c61016d85a391 100755 (executable)
@@ -101,7 +101,7 @@ test_from_inrelease_to_unsigned_with_override()
     # but that the individual packages are still considered untrusted
     testfailureequal "WARNING: The following packages cannot be authenticated!
   evil
-E: There are problems and -y was used without --force-yes" aptget install -qq -y evil
+E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y evil
 }
 
 test_cve_2012_0214()
index 646484e7b1b2a108fdba0fc2be3eca7e6cb8e935..503b819851decbdda39d3a469607d2a954a50cd9 100755 (executable)
@@ -120,7 +120,7 @@ test_unauthenticated_to_invalid_inrelease() {
     listcurrentlistsdirectory > lists.before
     testfailureequal "WARNING: The following packages cannot be authenticated!
   old
-E: There are problems and -y was used without --force-yes" aptget install -qq -y old
+E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y old
 
     # go to authenticated but not correct
     add_new_package '+1hour'
@@ -133,7 +133,7 @@ E: Some index files failed to download. They have been ignored, or old ones used
     testfailure ls rootdir/var/lib/apt/lists/*_InRelease
     testfailureequal "WARNING: The following packages cannot be authenticated!
   old
-E: There are problems and -y was used without --force-yes" aptget install -qq -y old
+E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y old
 }
 
 test_inrelease_to_unauth_inrelease() {
index 62355a6b58ca1c6c6f91478838ae6417dcd02ead..93a33d30f2638c13ff3c0cad206288f6f556b378 100755 (executable)
@@ -48,7 +48,7 @@ DPkg::Tools::options::\"./${hook}-v${1}.sh\"::Version \"$1\";" > rootdir/etc/apt
 observehook() {
        rm -f ${hook}-v2.list ${hook}-v3.list
        msgtest 'Observe hooks while' "$*"
-       testsuccess --nomsg aptget "$@" -y --force-yes
+       testsuccess --nomsg aptget "$@" -y --allow-downgrades
 }
 
 testrun() {
index 06701c62307f1addcd1bf6d6b4707af68037d78e..c4d1455ebed44424deab202010ea1d57f0bfd66d 100755 (executable)
@@ -69,7 +69,7 @@ The following NEW packages will be installed:
 After this operation, 5370 kB of additional disk space will be used.
 WARNING: The following packages cannot be authenticated!
   apt
-E: There are problems and -y was used without --force-yes' aptget install apt -dy
+E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy
 }
 
 failaptnew() {
@@ -83,7 +83,7 @@ The following NEW packages will be installed:
 After this operation, 5808 kB of additional disk space will be used.
 WARNING: The following packages cannot be authenticated!
   apt
-E: There are problems and -y was used without --force-yes' aptget install apt -dy
+E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy
 }
 
 # fake our downloadable file