v1-0001-Don-t-strip-libdir-from-LOAD-command.patch

application/octet-stream

Filename: v1-0001-Don-t-strip-libdir-from-LOAD-command.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #18920: LOAD '$libdir/plugins' no longer works in 18beta1

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0001
Subject: Don't strip $libdir from LOAD command
File+
src/backend/utils/fmgr/dfmgr.c 8 8
From 05af0217ae625200b580fe9582510a4db88a6ead Mon Sep 17 00:00:00 2001
From: Matheus Alcantara <mths.dev@pm.me>
Date: Mon, 2 Jun 2025 11:01:20 -0300
Subject: [PATCH v1 1/2] Don't strip $libdir from LOAD command

The 4f7f7b03758 commit implement the extension_control_path GUC, and to
make it work it was decided that we should strip the $libdir/ on
module_pathname from .control files, so that extensions don't need to
worry about this change.

This strip logic was implemented on expand_dynamic_library_name() which
works fine when executing the SQL functions from extensions but this
function is also called when the LOAD command is executed, and since the
user may explicitly pass the $libdir prefix on LOAD parameter we should
not strip in this case.

This commit fix this issue by moving the strip logic from
expand_dynamic_library_name() to load_external_function() that is called
when the running the SQL script from extensions.
---
 src/backend/utils/fmgr/dfmgr.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 603632581d0..4bb84ff7087 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -99,6 +99,14 @@ load_external_function(const char *filename, const char *funcname,
 	void	   *lib_handle;
 	void	   *retval;
 
+	/*
+	 * If the value starts with "$libdir/", strip that.  This is because many
+	 * extensions have hardcoded '$libdir/foo' as their library name, which
+	 * prevents using the path.
+	 */
+	if (strncmp(filename, "$libdir/", 8) == 0)
+		filename += 8;
+
 	/* Expand the possibly-abbreviated filename to an exact path name */
 	fullname = expand_dynamic_library_name(filename);
 
@@ -456,14 +464,6 @@ expand_dynamic_library_name(const char *name)
 
 	Assert(name);
 
-	/*
-	 * If the value starts with "$libdir/", strip that.  This is because many
-	 * extensions have hardcoded '$libdir/foo' as their library name, which
-	 * prevents using the path.
-	 */
-	if (strncmp(name, "$libdir/", 8) == 0)
-		name += 8;
-
 	have_slash = (first_dir_separator(name) != NULL);
 
 	if (!have_slash)
-- 
2.39.5 (Apple Git-154)