pgbackrest.git / summary / log / commit / refs
commit 381aecae4eeb15c538318e95c3101fa07a6712d4
Author: David Steele <david@pgmasters.net>
Date: Fri Nov 22 19:30:56 2019 +0000
Fix walPath() when CWD is / and path is relative.
The function would return a // prefix in this case, which works fine but looks odd while debugging.
src/command/archive/common.c | 2 +-
test/src/module/command/archiveCommonTest.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/command/archive/common.c b/src/command/archive/common.c
index 0a6a7f7be..a3c9908b2 100644
--- a/src/command/archive/common.c
+++ b/src/command/archive/common.c
@@ -247,7 +247,7 @@ walPath(const String *walFile)
char currentWorkDir[4096];
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
- result = strNewFmt("%s/%s", currentWorkDir, strPtr(walFile));
+ result = strNewFmt("%s/%s", strcmp(currentWorkDir, "/") != 0 ? currentWorkDir : "", strPtr(walFile));
}
else
result = strDup(walFile);
diff --git a/test/src/module/command/archiveCommonTest.c b/test/src/module/command/archiveCommonTest.c
index 53c08a12d..5da809cd5 100644
--- a/test/src/module/command/archiveCommonTest.c
+++ b/test/src/module/command/archiveCommonTest.c
@@ -176,6 +176,10 @@ testRun(void)
TEST_RESULT_STR(strPtr(walPath(strNew("/absolute/path"))), "/absolute/path", "absolute path");
TEST_RESULT_STR(strPtr(walPath(strNew("relative/path"))), "/tmp/relative/path", "relative path");
+
+ THROW_ON_SYS_ERROR(chdir("/") != 0, PathMissingError, "unable to chdir()");
+
+ TEST_RESULT_STR(strPtr(walPath(strNew("relative/path"))), "/relative/path", "relative path");
}
// *****************************************************************************************************************************
[parent: 0c05df458287]