aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbpkg/manifest.cxx30
-rw-r--r--libbpkg/manifest.hxx21
2 files changed, 48 insertions, 3 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 8782409..b94b4da 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -1803,6 +1803,36 @@ namespace bpkg
parse_package_manifest (p, move (nv), iu, fl, *this);
}
+ static const string description_file ("description-file");
+ static const string changes_file ("changes-file");
+
+ void package_manifest::
+ load_files (const function<load_function>& loader)
+ {
+ auto load = [&loader] (const string& n, const path& p)
+ {
+ string r (loader (n, p));
+
+ if (r.empty ())
+ throw parsing ("package " + n + " references empty file");
+
+ return r;
+ };
+
+ // Load the description-file manifest value.
+ //
+ if (description && description->file)
+ description = text_file (load (description_file, description->path));
+
+ // Load the changes-file manifest values.
+ //
+ for (text_file& c: changes)
+ {
+ if (c.file)
+ c = text_file (load (changes_file, c.path));
+ }
+ }
+
static void
serialize_package_manifest (manifest_serializer& s,
const package_manifest& m,
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index fc61511..3d8f5f5 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -9,10 +9,11 @@
#include <string>
#include <vector>
#include <cassert>
-#include <cstdint> // uint16_t
+#include <cstdint> // uint16_t
#include <ostream>
-#include <utility> // move()
-#include <stdexcept> // logic_error
+#include <utility> // move()
+#include <stdexcept> // logic_error
+#include <functional>
#include <libbutl/url.mxx>
#include <libbutl/path.mxx>
@@ -634,6 +635,20 @@ namespace bpkg
//
void
serialize_header (butl::manifest_serializer&) const;
+
+ // Load the *-file manifest values using the specified load function that
+ // returns the file contents passing through any exception it may throw.
+ //
+ // Note that if the returned file contents is empty, load_files() makes
+ // sure that this is allowed by the value's semantics throwing
+ // manifest_parsing otherwise. However, the load function may want to
+ // recognize such cases itself in order to issue more precise diagnostics.
+ //
+ using load_function = std::string (const std::string& name,
+ const butl::path& value);
+
+ void
+ load_files (const std::function<load_function>&);
};
// Create individual package manifest.