commit 08f168ab38d635f9e33480b506f3a0d667f80244 Author: Álvaro Herrera [Álvaro Herrera ] AuthorDate: Tue Nov 11 15:48:45 2025 +0100 CommitDate: Tue Nov 11 15:48:45 2025 +0100 []review changes diff --git a/src/backend/catalog/pg_tablespace.c b/src/backend/catalog/pg_tablespace.c index c00888456c8..d23aa7ae274 100644 --- a/src/backend/catalog/pg_tablespace.c +++ b/src/backend/catalog/pg_tablespace.c @@ -3,7 +3,7 @@ * pg_tablespace.c * routines to support tablespaces * - * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group + * Portions Copyright (c) 2011-2025, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * @@ -14,6 +14,7 @@ */ #include "postgres.h" +#include #include #include "catalog/pg_tablespace.h" @@ -22,25 +23,21 @@ /* - * get_tablespace_loc_string - Get a tablespace's location as a C-string for a - * tablespace from its OID. + * get_tablespace_location + * Get a tablespace's location as a C-string, by its OID */ char * -get_tablespace_loc_string(Oid tablespaceOid) +get_tablespace_location(Oid tablespaceOid) { - char sourcepath[MAXPGPATH] = {'\0'}; - char targetpath[MAXPGPATH] = {'\0'}; + char sourcepath[MAXPGPATH]; + char targetpath[MAXPGPATH]; int rllen; struct stat st; - StringInfoData buf; - - initStringInfo(&buf); - appendStringInfoString(&buf, ""); /* - * It's useful to apply this function to pg_class.reltablespace, wherein - * zero means "the database's default tablespace". So, rather than - * throwing an error for zero, we choose to assume that's what is meant. + * It's useful to apply this to pg_class.reltablespace, wherein zero means + * "the database's default tablespace". So, rather than throwing an error + * for zero, we choose to assume that's what is meant. */ if (tablespaceOid == InvalidOid) tablespaceOid = MyDatabaseTableSpace; @@ -50,7 +47,7 @@ get_tablespace_loc_string(Oid tablespaceOid) */ if (tablespaceOid == DEFAULTTABLESPACE_OID || tablespaceOid == GLOBALTABLESPACE_OID) - return buf.data; + return pstrdup(""); /* * Find the location of the tablespace by reading the symbolic link that @@ -65,36 +62,29 @@ get_tablespace_loc_string(Oid tablespaceOid) * found, a relative path to the data directory is returned. */ if (lstat(sourcepath, &st) < 0) - { ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not stat file \"%s\": %m", - sourcepath))); - } + errcode_for_file_access(), + errmsg("could not stat file \"%s\": %m", + sourcepath)); if (!S_ISLNK(st.st_mode)) - { - appendStringInfoString(&buf, sourcepath); - return buf.data; - } + return pstrdup(sourcepath); /* - * In presence of a link or a junction point, return the path pointing to. + * In presence of a link or a junction point, return the path pointed to. */ rllen = readlink(sourcepath, targetpath, sizeof(targetpath)); if (rllen < 0) ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not read symbolic link \"%s\": %m", - sourcepath))); + errcode_for_file_access(), + errmsg("could not read symbolic link \"%s\": %m", + sourcepath)); if (rllen >= sizeof(targetpath)) ereport(ERROR, - (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("symbolic link \"%s\" target is too long", - sourcepath))); + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("symbolic link \"%s\" target is too long", + sourcepath)); targetpath[rllen] = '\0'; - appendStringInfoString(&buf, targetpath); - - return buf.data; + return pstrdup(targetpath); } diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index cb99d7435eb..a365c432d34 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -318,7 +318,7 @@ pg_tablespace_location(PG_FUNCTION_ARGS) char *tablespaceLoc; /* Get LOCATION string from its OID */ - tablespaceLoc = get_tablespace_loc_string(tablespaceOid); + tablespaceLoc = get_tablespace_location(tablespaceOid); PG_RETURN_TEXT_P(cstring_to_text(tablespaceLoc)); } diff --git a/src/include/catalog/pg_tablespace.h b/src/include/catalog/pg_tablespace.h index f065cff9ddc..7816d779d8c 100644 --- a/src/include/catalog/pg_tablespace.h +++ b/src/include/catalog/pg_tablespace.h @@ -54,6 +54,6 @@ DECLARE_UNIQUE_INDEX(pg_tablespace_spcname_index, 2698, TablespaceNameIndexId, p MAKE_SYSCACHE(TABLESPACEOID, pg_tablespace_oid_index, 4); -extern char *get_tablespace_loc_string(Oid tablespaceOid); +extern char *get_tablespace_location(Oid tablespaceOid); #endif /* PG_TABLESPACE_H */