From a5f63f6391ae18138ae5c09408831ee70ad02180 Mon Sep 17 00:00:00 2001 From: wuyuechuan Date: Fri, 11 Sep 2020 14:46:53 +0800 Subject: [PATCH] gs_basebackup: tablespace_mapping option doesn't work --- src/bin/pg_basebackup/pg_basebackup.cpp | 8 ++++---- src/common/backend/utils/adt/misc.cpp | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bin/pg_basebackup/pg_basebackup.cpp b/src/bin/pg_basebackup/pg_basebackup.cpp index 8dd3f3f3b..8791efec4 100644 --- a/src/bin/pg_basebackup/pg_basebackup.cpp +++ b/src/bin/pg_basebackup/pg_basebackup.cpp @@ -247,7 +247,7 @@ static void tablespace_list_create() securec_check_c(rcm, "", ""); } -static void save_tablespace_dir(char* dir) +static void save_tablespace_dir(const char* dir) { if (tblspaceDirectory != NULL) { tblspaceDirectory[tblspaceIndex] = xstrdup(dir); @@ -1268,10 +1268,10 @@ static void BaseBackup(void) tablespacepath); securec_check_ss_c(rc, "\0", "\0"); - verify_dir_is_empty_or_create(nodetablespacepath); - + const char* mappingSpacePath = get_tablespace_mapping(nodetablespacepath); + verify_dir_is_empty_or_create((char*)mappingSpacePath); /* Save the tablespace directory here so we can remove it when errors happen. */ - save_tablespace_dir(nodetablespacepath); + save_tablespace_dir(mappingSpacePath); } } diff --git a/src/common/backend/utils/adt/misc.cpp b/src/common/backend/utils/adt/misc.cpp index f6d559c76..ead4c1264 100755 --- a/src/common/backend/utils/adt/misc.cpp +++ b/src/common/backend/utils/adt/misc.cpp @@ -737,7 +737,9 @@ Datum pg_tablespace_location(PG_FUNCTION_ARGS) target_path[rllen] = '\0'; /* relative location will contain t_thrd.proc_cxt.DataDir */ - if (0 == strncmp(target_path, t_thrd.proc_cxt.DataDir, strlen(t_thrd.proc_cxt.DataDir))) { + size_t dataDirLength = strlen(t_thrd.proc_cxt.DataDir); + if (0 == strncmp(target_path, t_thrd.proc_cxt.DataDir, dataDirLength) && rllen > dataDirLength && + target_path[dataDirLength] == '/') { /* * The position is not '/' when skip t_thrd.proc_cxt.DataDir. the relative location can't start from '/' * We only need get the relative location, so remove the common prefix