summaryrefslogtreecommitdiff
path: root/apt-private
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 /apt-private
parentde86a4b076a37db2f70ee5fbfbb295cc71c344df (diff)
json: Add `package-list` and `statistics` install hooks
This enables hooks to output additional information.
Diffstat (limited to 'apt-private')
-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
4 files changed, 21 insertions, 11 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);