1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-13 01:00:23 +02:00

Use getcwd() to construct path when WAL path is relative.

Using pg1-path, as we were doing previously, could lead to WAL being copied to/from unexpected places.  PostgreSQL sets the current working directory to PGDATA so we can use that to resolve relative paths.
This commit is contained in:
David Steele
2019-10-30 14:55:25 +01:00
parent e06db21e35
commit 7168e07440
7 changed files with 22 additions and 40 deletions

View File

@ -172,15 +172,10 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("walPath()"))
{
TEST_RESULT_STR(
strPtr(walPath(strNew("/absolute/path"), strNew("/pg"), strNew("test"))), "/absolute/path", "absolute path");
TEST_RESULT_STR(
strPtr(walPath(strNew("relative/path"), strNew("/pg"), strNew("test"))), "/pg/relative/path", "relative path");
TEST_ERROR(
walPath(strNew("relative/path"), NULL, strNew("test")), OptionRequiredError,
"option 'pg1-path' must be specified when relative wal paths are used\n"
"HINT: is %f passed to test instead of %p?\n"
"HINT: PostgreSQL may pass relative paths even with %p depending on the environment.");
THROW_ON_SYS_ERROR(chdir("/tmp") != 0, PathMissingError, "unable to chdir()");
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");
}
// *****************************************************************************************************************************