Merge pull request #336298 from eljamm/taler-merchant

taler-merchant: fix wrong templates and spa dirs
This commit is contained in:
Weijia Wang 2024-08-21 20:04:15 +02:00 committed by GitHub
commit c9ec828978
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 97 additions and 4 deletions

View File

@ -0,0 +1,75 @@
From 3ca51717bbb7643eb0629729d0680cca75ce34c8 Mon Sep 17 00:00:00 2001
From: eljamm <fedi.jamoussi@protonmail.ch>
Date: Wed, 14 Aug 2024 11:14:41 +0100
Subject: [PATCH] add TALER_TEMPLATING_init_path
The merchant uses `TALER_TEMPLATING_init` function from the exchange's
headers, which makes it harder to patch in the correct directory.
To circumvent this, a similar function that takes the templates path
directly is added.
---
src/include/taler_templating_lib.h | 9 +++++++++
src/templating/templating_api.c | 25 +++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/src/include/taler_templating_lib.h b/src/include/taler_templating_lib.h
index 6af6db715..343004ef1 100644
--- a/src/include/taler_templating_lib.h
+++ b/src/include/taler_templating_lib.h
@@ -120,6 +120,16 @@ TALER_TEMPLATING_reply_error (struct MHD_Connection *connection,
enum GNUNET_GenericReturnValue
TALER_TEMPLATING_init (const char *subsystem);
+/**
+ * Preload templates from path.
+ *
+ * @param subsystem name of the subsystem, "merchant" or "exchange"
+ * @param path name of the absolute template path
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_init_path (const char *subsystem, const char *path);
+
/**
* Nicely shut down templating subsystem.
diff --git a/src/templating/templating_api.c b/src/templating/templating_api.c
index 88a17c682..a9afa2b70 100644
--- a/src/templating/templating_api.c
+++ b/src/templating/templating_api.c
@@ -506,6 +506,31 @@ TALER_TEMPLATING_init (const char *subsystem)
}
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_init_path (const char *subsystem, const char *path)
+{
+ char *dn;
+ int ret;
+
+ {
+ GNUNET_asprintf (&dn,
+ "%s/%s/templates/",
+ path,
+ subsystem);
+ }
+ ret = GNUNET_DISK_directory_scan (dn,
+ &load_template,
+ NULL);
+ GNUNET_free (dn);
+ if (-1 == ret)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
void
TALER_TEMPLATING_done (void)
{
--
2.45.2

View File

@ -34,6 +34,8 @@ stdenv.mkDerivation {
hash = "sha256-yHRRMlqFA2OiFg0rBVzn7130wyVaxKn2dChFTPnVtbs=";
};
patches = [ ./0001-add-TALER_TEMPLATING_init_path.patch ];
nativeBuildInputs = [
autoreconfHook
pkg-config

View File

@ -8,6 +8,7 @@
libtool,
pkg-config,
autoreconfHook,
makeWrapper,
jq,
}:
@ -36,9 +37,20 @@ stdenv.mkDerivation {
ln -s ${taler-wallet-core}/spa.html $sourceRoot/contrib/
'';
# Use an absolute path for `templates` and `spa` directories, else a relative
# path to the `taler-exchange` package is used.
postPatch = ''
substituteInPlace src/backend/taler-merchant-httpd.c \
--replace-fail 'TALER_TEMPLATING_init ("merchant");' "TALER_TEMPLATING_init_path (\"merchant\", \"$out/share/taler\");"
substituteInPlace src/backend/taler-merchant-httpd_spa.c \
--replace-fail 'GNUNET_DISK_directory_scan (dn,' "GNUNET_DISK_directory_scan (\"$out/share/taler/merchant/spa/\","
'';
nativeBuildInputs = [
pkg-config
autoreconfHook
makeWrapper
];
buildInputs = taler-exchange.buildInputs ++ [
@ -59,10 +71,14 @@ stdenv.mkDerivation {
popd
'';
configureFlags = [
"--with-gnunet=${gnunet}"
"--with-exchange=${taler-exchange}"
];
# NOTE: The executables that need database access fail to detect the
# postgresql library in `$out/lib/taler`, so we need to wrap them.
postInstall = ''
for exec in dbinit httpd webhook wirewatch depositcheck exchange; do
wrapProgram $out/bin/taler-merchant-$exec \
--prefix LD_LIBRARY_PATH : "$out/lib/taler"
done
'';
enableParallelBuilding = true;