summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2021-04-23 10:36:18 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2021-04-23 12:26:46 +0200
commitdc11a4422d99cb49817c827b9f827617b5880600 (patch)
treed0aace43cbc022e674e6101bb7262b53a4924244
parentde86a4b076a37db2f70ee5fbfbb295cc71c344df (diff)
json: Add `package-list` and `statistics` install hooks
This enables hooks to output additional information.
-rw-r--r--apt-private/private-install.cc11
-rw-r--r--apt-private/private-install.h6
-rw-r--r--apt-private/private-json-hooks.cc13
-rw-r--r--apt-private/private-upgrade.cc2
-rw-r--r--doc/json-hooks-protocol.md8
-rwxr-xr-xtest/integration/test-apt-cli-json-hooks24
6 files changed, 52 insertions, 12 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 402f8f4b6..0c26c4275 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -100,7 +100,7 @@ static void RemoveDownloadNeedingItemsFromFetcher(pkgAcquire &Fetcher, bool &Tra
I = Fetcher.ItemsBegin();
}
}
-bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
+bool InstallPackages(CacheFile &Cache, bool ShwKept, bool Ask, bool Safety, std::string const &Hook, CommandLine const &CmdL)
{
if (not RunScripts("APT::Install::Pre-Invoke"))
return false;
@@ -168,7 +168,12 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
if (_config->FindB("APT::Get::Download-Only",false) == false)
Essential = !ShowEssential(c1out,Cache);
+ if (not Hook.empty())
+ RunJsonHook(Hook, "org.debian.apt.hooks.install.package-list", CmdL.FileList, Cache);
+
Stats(c1out,Cache);
+ if (not Hook.empty())
+ RunJsonHook(Hook, "org.debian.apt.hooks.install.statistics", CmdL.FileList, Cache);
// Sanity check
if (Cache->BrokenCount() != 0)
@@ -944,9 +949,9 @@ bool DoInstall(CommandLine &CmdL)
// See if we need to prompt
// FIXME: check if really the packages in the set are going to be installed
if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0)
- result = InstallPackages(Cache, false, false);
+ result = InstallPackages(Cache, false, false, true, "AptCli::Hooks::Install", CmdL);
else
- result = InstallPackages(Cache, false);
+ result = InstallPackages(Cache, false, true, true, "AptCli::Hooks::Install", CmdL);
if (result)
result = RunJsonHook("AptCli::Hooks::Install", "org.debian.apt.hooks.install.post", CmdL.FileList, Cache);
diff --git a/apt-private/private-install.h b/apt-private/private-install.h
index 39a040e7d..52f055963 100644
--- a/apt-private/private-install.h
+++ b/apt-private/private-install.h
@@ -36,8 +36,10 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg
bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache, int UpgradeMode);
bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode);
-APT_PUBLIC bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
- bool Safety = true);
+APT_PUBLIC bool InstallPackages(CacheFile &Cache, bool ShwKept, bool Ask = true,
+ bool Safety = true,
+ std::string const &Hook = "",
+ CommandLine const &CmdL = {});
bool CheckNothingBroken(CacheFile &Cache);
bool DoAutomaticRemove(CacheFile &Cache);
diff --git a/apt-private/private-json-hooks.cc b/apt-private/private-json-hooks.cc
index 652a59812..a40597e0a 100644
--- a/apt-private/private-json-hooks.cc
+++ b/apt-private/private-json-hooks.cc
@@ -277,11 +277,14 @@ static void NotifyHook(std::ostream &os, std::string const &method, const char *
/* Build params */
jsonWriter.name("params").beginObject();
- jsonWriter.name("command").value(FileList[0]);
- jsonWriter.name("search-terms").beginArray();
- for (int i = 1; FileList[i] != NULL; i++)
- jsonWriter.value(FileList[i]);
- jsonWriter.endArray();
+ if (FileList != nullptr)
+ {
+ jsonWriter.name("command").value(FileList[0]);
+ jsonWriter.name("search-terms").beginArray();
+ for (int i = 1; FileList[i] != NULL; i++)
+ jsonWriter.value(FileList[i]);
+ jsonWriter.endArray();
+ }
jsonWriter.name("unknown-packages").beginArray();
for (auto const &PkgName : UnknownPackages)
jsonWriter.value(PkgName);
diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc
index a87ffbc46..c41e4d2f3 100644
--- a/apt-private/private-upgrade.cc
+++ b/apt-private/private-upgrade.cc
@@ -34,7 +34,7 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags)
return false;
}
RunJsonHook("AptCli::Hooks::Upgrade", "org.debian.apt.hooks.install.pre-prompt", CmdL.FileList, Cache);
- if (InstallPackages(Cache, true))
+ if (InstallPackages(Cache, true, true, true, "AptCli::Hooks::Upgrade", CmdL))
return RunJsonHook("AptCli::Hooks::Upgrade", "org.debian.apt.hooks.install.post", CmdL.FileList, Cache);
else
return RunJsonHook("AptCli::Hooks::Upgrade", "org.debian.apt.hooks.install.fail", CmdL.FileList, Cache);
diff --git a/doc/json-hooks-protocol.md b/doc/json-hooks-protocol.md
index 489b04843..3c7f6e4f2 100644
--- a/doc/json-hooks-protocol.md
+++ b/doc/json-hooks-protocol.md
@@ -57,7 +57,9 @@ method `org.debian.apt.hooks.bye`.
The following methods are supported:
-1. `org.debian.apt.hooks.install.pre-prompt` - Run before the y/n prompt
+1. `org.debian.apt.hooks.install.pre-prompt` - Run before the package list and y/n prompt
+1. `org.debian.apt.hooks.install.package-list` - (optional in 0.1) Run after the package list. You could display additional lists of packages here
+1. `org.debian.apt.hooks.install.statistics` - (optional in 0.1) Run after the package list. You could display additional lists of packages here
1. `org.debian.apt.hooks.install.post` - Run after success
1. `org.debian.apt.hooks.install.fail` - Run after failed install
1. `org.debian.apt.hooks.search.pre` - Run before search
@@ -93,6 +95,10 @@ install. Each package has the following attributes:
- *mode*: One of `install`, `deinstall`, `purge`, or `keep`. `keep`
is not exposed in 0.1. To determine an upgrade, check
that a current version is installed.
+- One of the following optional fields may be set to true to indicate a change relative to an installed version:
+ - *downgrade*: true if downgrading
+ - *upgrade*: true if upgrading
+ - *reinstall*: true if reinstall flag is set
- *automatic*: Whether the package is/will be automatically installed
- *versions*: An array with up to 3 fields:
diff --git a/test/integration/test-apt-cli-json-hooks b/test/integration/test-apt-cli-json-hooks
index 07801a547..0e6745d00 100755
--- a/test/integration/test-apt-cli-json-hooks
+++ b/test/integration/test-apt-cli-json-hooks
@@ -119,7 +119,19 @@ HOOK: empty
HOOK: BYE
The following NEW packages will be installed:
foo
+HOOK: HELLO
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
+HOOK: empty
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.package-list","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":2,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":2,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]},"install":{"id":2,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]}}}]}}
+HOOK: empty
+HOOK: BYE
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
+HOOK: HELLO
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
+HOOK: empty
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.statistics","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":2,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":2,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]},"install":{"id":2,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]}}}]}}
+HOOK: empty
+HOOK: BYE
Inst foo (1.0 Lemons:unstable [all])
Conf foo (1.0 Lemons:unstable [all])
HOOK: HELLO
@@ -154,7 +166,19 @@ HOOK: empty
HOOK: BYE
The following packages will be upgraded:
upgrade
+HOOK: HELLO
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
+HOOK: empty
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.package-list","params":{"command":"dist-upgrade","search-terms":[],"unknown-packages":[],"packages":[{"id":1,"name":"upgrade","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"2.0","architecture":"i386","pin":500,"origins":[{"archive":"testing","codename":"testing","origin":"Oranges","label":"Lemons","site":""}]},"install":{"id":1,"version":"2.0","architecture":"i386","pin":500,"origins":[{"archive":"testing","codename":"testing","origin":"Oranges","label":"Lemons","site":""}]},"current":{"id":4,"version":"1.0","architecture":"i386","pin":100,"origins":[]}}}]}}
+HOOK: empty
+HOOK: BYE
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+HOOK: HELLO
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
+HOOK: empty
+HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.statistics","params":{"command":"dist-upgrade","search-terms":[],"unknown-packages":[],"packages":[{"id":1,"name":"upgrade","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"2.0","architecture":"i386","pin":500,"origins":[{"archive":"testing","codename":"testing","origin":"Oranges","label":"Lemons","site":""}]},"install":{"id":1,"version":"2.0","architecture":"i386","pin":500,"origins":[{"archive":"testing","codename":"testing","origin":"Oranges","label":"Lemons","site":""}]},"current":{"id":4,"version":"1.0","architecture":"i386","pin":100,"origins":[]}}}]}}
+HOOK: empty
+HOOK: BYE
Inst upgrade [1.0] (2.0 Lemons:testing [i386])
Conf upgrade (2.0 Lemons:testing [i386])
HOOK: HELLO