1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

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.
This commit is contained in:
David Steele 2019-11-22 14:30:56 -05:00
parent 0c05df4582
commit 381aecae4e
2 changed files with 5 additions and 1 deletions

View File

@ -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);

View File

@ -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");
}
// *****************************************************************************************************************************