1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Automatically strip trailing slashes for repo-ls paths.

Trailing slashes in at least some of the repository storage types were preventing repo-ls from displaying any content (presumably due to storage-specific behavior).

Since the path with the slash should be equivalent to the path without the slash, just remove it if provided by the user.
This commit is contained in:
David Christensen 2022-02-23 13:53:02 -06:00 committed by GitHub
parent 53f1b25204
commit 6320712323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View File

@ -106,6 +106,17 @@
<p>Add backup LSNs to <cmd>info</cmd> command output.</p>
</release-item>
<release-item>
<github-pull-request id="1673"/>
<release-item-contributor-list>
<release-item-contributor id="david.christensen"/>
<release-item-reviewer id="david.steele"/>
</release-item-contributor-list>
<p>Automatically strip trailing slashes for <cmd>repo-ls</cmd> paths.</p>
</release-item>
<release-item>
<commit subject="Improve protocol module error test for protocolClientFree()."/>
<commit subject="Use normal error for protocol module error retry test."/>

View File

@ -125,7 +125,13 @@ storageListRender(IoWrite *write)
const String *path = NULL;
if (strLstSize(cfgCommandParam()) == 1)
{
path = strLstGet(cfgCommandParam(), 0);
// Make sure the path does not end with a slash unless it is only /
if (strEndsWith(path, FSLASH_STR) && strSize(path) > 1)
path = strPath(path);
}
else if (strLstSize(cfgCommandParam()) > 1)
THROW(ParamInvalidError, "only one path may be specified");

View File

@ -158,9 +158,19 @@ testRun(void)
TEST_RESULT_STR_Z(strNewBuf(output), "aaa\n", "check output");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("subdirectory");
TEST_TITLE("error on /");
StringList *argListTmp = strLstDup(argList);
strLstAddZ(argListTmp, "/");
HRN_CFG_LOAD(cfgCmdRepoLs, argListTmp);
TEST_ERROR(
storageListRender(ioBufferWriteNew(output)), AssertError, "absolute path '/' is not in base path '" TEST_PATH "/repo'");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("subdirectory");
argListTmp = strLstDup(argList);
strLstAddZ(argListTmp, "bbb");
HRN_CFG_LOAD(cfgCmdRepoLs, argListTmp);
@ -169,6 +179,18 @@ testRun(void)
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "subdirectory");
TEST_RESULT_STR_Z(strNewBuf(output), "ccc\n", "check output");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("subdirectory with /");
argListTmp = strLstDup(argList);
strLstAddZ(argListTmp, "bbb/");
HRN_CFG_LOAD(cfgCmdRepoLs, argListTmp);
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "subdirectory");
TEST_RESULT_STR_Z(strNewBuf(output), "ccc\n", "check output");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("redirect stdout to a file");