diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2023-04-11 16:37:51 +0200 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2023-05-02 15:16:54 +0200 |
commit | 3625351722e67903dc34993fe318e50863bd2d31 (patch) | |
tree | aea4848210f93530c23fae4c238d483f83acd108 | |
parent | aa8c9aad81b57da96e8ac7345d0024ee526c7714 (diff) |
Add apt install,upgrade,... -U,--update options
This runs update before opening the cache and sources.list for
installing/upgrading.
-rw-r--r-- | apt-private/private-cmndline.cc | 4 | ||||
-rw-r--r-- | apt-private/private-install.cc | 5 | ||||
-rw-r--r-- | apt-private/private-update.cc | 4 | ||||
-rw-r--r-- | apt-private/private-update.h | 1 | ||||
-rw-r--r-- | apt-private/private-upgrade.cc | 4 | ||||
-rw-r--r-- | doc/apt-get.8.xml | 14 | ||||
-rw-r--r-- | doc/examples/configure-index | 2 | ||||
-rwxr-xr-x | test/integration/test-apt-get-install-update | 111 |
8 files changed, 143 insertions, 2 deletions
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index f607c4ccc..765378ea2 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -189,13 +189,15 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const addArg(0, "reinstall", "APT::Get::ReInstall", 0); addArg(0, "solver", "APT::Solver", CommandLine::HasArg); addArg(0, "planner", "APT::Planner", CommandLine::HasArg); + addArg('U', "update", "APT::Update", 0); if (CmdMatches("upgrade")) { addArg(0, "new-pkgs", "APT::Get::Upgrade-Allow-New", CommandLine::Boolean); } } - else if (CmdMatches("update")) + + else if (CmdMatches("update") || CmdMatches("install")) { addArg(0, "list-cleanup", "APT::Get::List-Cleanup", 0); addArg(0, "allow-insecure-repositories", "Acquire::AllowInsecureRepositories", 0); diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 08d58a53c..13ed35e2a 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -36,6 +36,7 @@ #include <apt-private/private-install.h> #include <apt-private/private-json-hooks.h> #include <apt-private/private-output.h> +#include <apt-private/private-update.h> #include <apti18n.h> /*}}}*/ @@ -852,6 +853,10 @@ struct PkgIsExtraInstalled { bool DoInstall(CommandLine &CmdL) { CacheFile Cache; + + if (_config->FindB("APT::Update") && not DoUpdate()) + return false; + Cache.InhibitActionGroups(true); if (Cache.BuildSourceList() == false) return false; diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc index f1734fea2..d6f7d62dd 100644 --- a/apt-private/private-update.cc +++ b/apt-private/private-update.cc @@ -51,7 +51,11 @@ bool DoUpdate(CommandLine &CmdL) { if (CmdL.FileSize() != 1) return _error->Error(_("The update command takes no arguments")); + return DoUpdate(); +} +bool DoUpdate() +{ CacheFile Cache; // Get the source list diff --git a/apt-private/private-update.h b/apt-private/private-update.h index e584f70cf..8ca706c55 100644 --- a/apt-private/private-update.h +++ b/apt-private/private-update.h @@ -6,5 +6,6 @@ class CommandLine; APT_PUBLIC bool DoUpdate(CommandLine &CmdL); +APT_PUBLIC bool DoUpdate(); #endif diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 97603dc16..143879fe6 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -11,6 +11,7 @@ #include <apt-private/private-install.h> #include <apt-private/private-json-hooks.h> #include <apt-private/private-output.h> +#include <apt-private/private-update.h> #include <apt-private/private-upgrade.h> #include <iostream> @@ -21,6 +22,9 @@ // this is actually performing the various upgrade operations static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) { + if (_config->FindB("APT::Update") && not DoUpdate()) + return false; + CacheFile Cache; auto VolatileCmdL = GetPseudoPackages(Cache.GetSourceList(), CmdL, AddVolatileBinaryFile, ""); diff --git a/doc/apt-get.8.xml b/doc/apt-get.8.xml index 6d28fe116..f4d347c70 100644 --- a/doc/apt-get.8.xml +++ b/doc/apt-get.8.xml @@ -657,6 +657,20 @@ <listitem><para>Fail the update command if any error occured, even a transient one.</para></listitem> </varlistentry> + <varlistentry><term><option>-U</option></term><term><option>--update</option></term> + <listitem><para>Run the <option>update</option> command before the specified command. This is supported for commands + installing, removing, or upgrading packages such as + <option>install</option>, <option>remove</option>, <option>safe-upgrade</option>, <option>full-upgrade</option>. + This can be useful to ensure a command always installs the latest versions, or, in combination with the + <option>--snapshot</option> option to make sure the snapshot is present when install is being run. + </para> + <para>Caveat: Due to technical limitations, locks are acquired individually for each phase, hence an install + may fail to acquire locks after successfully executing the update. Until this is resolved, this is merely + syntactic sugar for <literal>apt update && apt install</literal></para> + </listitem> + </varlistentry> + + &apt-commonoptions; </variablelist> diff --git a/doc/examples/configure-index b/doc/examples/configure-index index beafbbcd4..5ec209766 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -170,7 +170,7 @@ APT DropTranslation "<BOOL>"; }; - Update + Update "<BOOL>" { Pre-Invoke {"touch /var/lib/apt/pre-update-stamp"; }; Post-Invoke {"touch /var/lib/apt/post-update-stamp"; }; diff --git a/test/integration/test-apt-get-install-update b/test/integration/test-apt-get-install-update new file mode 100755 index 000000000..33be6e3c7 --- /dev/null +++ b/test/integration/test-apt-get-install-update @@ -0,0 +1,111 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" + +setupenvironment +configarchitecture 'amd64' + +buildsimplenativepackage 'awesome' 'native' '42' 'stable' +buildsimplenativepackage 'foo' 'all' '1.0' 'stable' +buildsimplenativepackage 'libbar' 'all' '1.0' 'stable' + +setupaptarchive --no-update +changetowebserver +testfailureequal "Reading package lists... +Building dependency tree... +E: Unable to locate package awesome" aptget install awesome -s + +msgmsg "apt-get {install,remove} {-U, --update}" +for command in install remove; do + for option in -U --update; do +testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} stable InRelease [$(stat -c %s aptarchive/dists/stable/InRelease) B] +Get:2 http://localhost:${APTHTTPPORT} stable/main Sources [$(stat -c %s aptarchive/dists/stable/main/source/Sources.gz) B] +Get:3 http://localhost:${APTHTTPPORT} stable/main amd64 Packages [$(stat -c %s aptarchive/dists/stable/main/binary-amd64/Packages.gz) B] +Get:4 http://localhost:${APTHTTPPORT} stable/main all Packages [$(stat -c %s aptarchive/dists/stable/main/binary-all/Packages.gz) B] +Get:5 http://localhost:${APTHTTPPORT} stable/main Translation-en [$(stat -c %s aptarchive/dists/stable/main/i18n/Translation-en.gz) B] +Reading package lists... +Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + awesome +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst awesome (42 stable [amd64]) +Conf awesome (42 stable [amd64])" \ + aptget $command $option awesome+ -s + find rootdir/var/lib/apt/lists/ -type f -delete + done +done + +msgmsg "apt {install,remove} {-U, --update}" + +for command in install remove; do + for option in -U --update; do +testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} stable InRelease [$(stat -c %s aptarchive/dists/stable/InRelease) B] +Get:2 http://localhost:${APTHTTPPORT} stable/main Sources [$(stat -c %s aptarchive/dists/stable/main/source/Sources.gz) B] +Get:3 http://localhost:${APTHTTPPORT} stable/main amd64 Packages [$(stat -c %s aptarchive/dists/stable/main/binary-amd64/Packages.gz) B] +Get:4 http://localhost:${APTHTTPPORT} stable/main all Packages [$(stat -c %s aptarchive/dists/stable/main/binary-all/Packages.gz) B] +Get:5 http://localhost:${APTHTTPPORT} stable/main Translation-en [$(stat -c %s aptarchive/dists/stable/main/i18n/Translation-en.gz) B] +Reading package lists... +Building dependency tree... +All packages are up to date. +Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + awesome +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst awesome (42 stable [amd64]) +Conf awesome (42 stable [amd64])" \ + apt $command $option awesome+ -s + find rootdir/var/lib/apt/lists/ -type f -delete + done +done + +msgmsg "apt-get *upgrade {-U, --update}" + +for command in upgrade dist-upgrade full-upgrade; do + for option in -U --update; do +testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} stable InRelease [$(stat -c %s aptarchive/dists/stable/InRelease) B] +Get:2 http://localhost:${APTHTTPPORT} stable/main Sources [$(stat -c %s aptarchive/dists/stable/main/source/Sources.gz) B] +Get:3 http://localhost:${APTHTTPPORT} stable/main amd64 Packages [$(stat -c %s aptarchive/dists/stable/main/binary-amd64/Packages.gz) B] +Get:4 http://localhost:${APTHTTPPORT} stable/main all Packages [$(stat -c %s aptarchive/dists/stable/main/binary-all/Packages.gz) B] +Get:5 http://localhost:${APTHTTPPORT} stable/main Translation-en [$(stat -c %s aptarchive/dists/stable/main/i18n/Translation-en.gz) B] +Reading package lists... +Reading package lists... +Building dependency tree... +Calculating upgrade... +The following NEW packages will be installed: + awesome +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst awesome (42 stable [amd64]) +Conf awesome (42 stable [amd64])" \ + aptget $command $option awesome -s + find rootdir/var/lib/apt/lists/ -type f -delete + done +done + +msgmsg "apt *upgrade {-U, --update}" + +for command in upgrade dist-upgrade full-upgrade; do + for option in -U --update; do +testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} stable InRelease [$(stat -c %s aptarchive/dists/stable/InRelease) B] +Get:2 http://localhost:${APTHTTPPORT} stable/main Sources [$(stat -c %s aptarchive/dists/stable/main/source/Sources.gz) B] +Get:3 http://localhost:${APTHTTPPORT} stable/main amd64 Packages [$(stat -c %s aptarchive/dists/stable/main/binary-amd64/Packages.gz) B] +Get:4 http://localhost:${APTHTTPPORT} stable/main all Packages [$(stat -c %s aptarchive/dists/stable/main/binary-all/Packages.gz) B] +Get:5 http://localhost:${APTHTTPPORT} stable/main Translation-en [$(stat -c %s aptarchive/dists/stable/main/i18n/Translation-en.gz) B] +Reading package lists... +Building dependency tree... +All packages are up to date. +Reading package lists... +Building dependency tree... +Calculating upgrade... +The following NEW packages will be installed: + awesome +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst awesome (42 stable [amd64]) +Conf awesome (42 stable [amd64])" \ + apt $command $option awesome -s + find rootdir/var/lib/apt/lists/ -type f -delete + done +done |