summaryrefslogtreecommitdiff
path: root/apt-private/private-json-hooks.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2021-04-22 10:45:45 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2021-04-23 12:26:46 +0200
commit4b5215e8e2e31637cb0998ecb80d3c3146760579 (patch)
tree0bf71b1dc2a60c88fca02c7fad1a567e1a15f218 /apt-private/private-json-hooks.cc
parent949f3821268943149ddc26d4eaee3bfbaa1255a9 (diff)
json: Add origins fields to version
Provide access to the origins of a package, such that tools can display information about them; for example, you can write a hook counting security upgrades.
Diffstat (limited to 'apt-private/private-json-hooks.cc')
-rw-r--r--apt-private/private-json-hooks.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/apt-private/private-json-hooks.cc b/apt-private/private-json-hooks.cc
index 6bf70b1c6..652a59812 100644
--- a/apt-private/private-json-hooks.cc
+++ b/apt-private/private-json-hooks.cc
@@ -199,6 +199,33 @@ class APT_HIDDEN JsonWriter
};
/**
+ * @brief Write a VerFileIterator to a JsonWriter
+ */
+static void verFiletoJson(JsonWriter &writer, CacheFile &, pkgCache::VerFileIterator const &vf)
+{
+ auto pf = vf.File(); // Packages file
+ auto rf = pf.ReleaseFile(); // release file
+
+ writer.beginObject();
+ if (not rf.end()) {
+ if (rf->Archive != 0)
+ writer.name("archive").value(rf.Archive());
+ if (rf->Codename != 0)
+ writer.name("codename").value(rf.Codename());
+ if (rf->Version != 0)
+ writer.name("version").value(rf.Version());
+ if (rf->Origin != 0)
+ writer.name("origin").value(rf.Origin());
+ if (rf->Label != 0)
+ writer.name("label").value(rf.Label());
+ if (rf->Site != 0)
+ writer.name("site").value(rf.Site());
+ }
+
+ writer.endObject();
+}
+
+/**
* @brief Write a VerIterator to a JsonWriter
*/
static void verIterToJson(JsonWriter &writer, CacheFile &Cache, pkgCache::VerIterator const &Ver)
@@ -208,6 +235,14 @@ static void verIterToJson(JsonWriter &writer, CacheFile &Cache, pkgCache::VerIte
writer.name("version").value(Ver.VerStr());
writer.name("architecture").value(Ver.Arch());
writer.name("pin").value(Cache->GetPolicy().GetPriority(Ver));
+
+ writer.name("origins");
+ writer.beginArray();
+ for (auto vf = Ver.FileList(); !vf.end(); vf++)
+ if ((vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
+ verFiletoJson(writer, Cache, vf);
+ writer.endArray();
+
writer.endObject();
}