summaryrefslogtreecommitdiff
path: root/apt-private/private-search.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2018-04-13 12:32:35 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2018-04-15 21:11:42 +0200
commite9796b9c21ee7d8e8f5d6e2a24db43fc4368b557 (patch)
tree110d8fd225b790e491793e3619f470548b3e9c5a /apt-private/private-search.cc
parent03cc48f6c6591d762c27f9b5c8627b267a7158e2 (diff)
Introduce experimental new hooks for command-line tools
This allows third-party package managers like snap or flatpak to hook in and suggest alternatives if packages could not be found, for example. This is still highly experimental and the protocol might change in future versions.
Diffstat (limited to 'apt-private/private-search.cc')
-rw-r--r--apt-private/private-search.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc
index eac7abd05..52a52e522 100644
--- a/apt-private/private-search.cc
+++ b/apt-private/private-search.cc
@@ -12,7 +12,9 @@
#include <apt-pkg/policy.h>
#include <apt-pkg/progress.h>
+#include <apt-private/private-cachefile.h>
#include <apt-private/private-cacheset.h>
+#include <apt-private/private-json-hooks.h>
#include <apt-private/private-output.h>
#include <apt-private/private-search.h>
#include <apt-private/private-show.h>
@@ -29,7 +31,9 @@
static bool FullTextSearch(CommandLine &CmdL) /*{{{*/
{
- pkgCacheFile CacheFile;
+
+ CacheFile CacheFile;
+ CacheFile.GetDepCache();
pkgCache *Cache = CacheFile.GetPkgCache();
pkgDepCache::Policy *Plcy = CacheFile.GetPolicy();
if (unlikely(Cache == NULL || Plcy == NULL))
@@ -40,6 +44,8 @@ static bool FullTextSearch(CommandLine &CmdL) /*{{{*/
if (NumPatterns < 1)
return _error->Error(_("You must give at least one search pattern"));
+ RunJsonHook("AptCli::Hooks::Search", "org.debian.apt.hooks.search.pre", CmdL.FileList, CacheFile);
+
#define APT_FREE_PATTERNS() for (std::vector<regex_t>::iterator P = Patterns.begin(); \
P != Patterns.end(); ++P) { regfree(&(*P)); }
@@ -127,6 +133,10 @@ static bool FullTextSearch(CommandLine &CmdL) /*{{{*/
for (K = output_map.begin(); K != output_map.end(); ++K)
std::cout << (*K).second << std::endl;
+ if (output_map.empty())
+ RunJsonHook("AptCli::Hooks::Search", "org.debian.apt.hooks.search.fail", CmdL.FileList, CacheFile);
+ else
+ RunJsonHook("AptCli::Hooks::Search", "org.debian.apt.hooks.search.post", CmdL.FileList, CacheFile);
return true;
}
/*}}}*/