pgbackrest.git / summary / log / commit / refs
commit 41f9d69edcf671fbda21cb6d87dbca08e48e9976
Author: David Steele <david@pgmasters.net>
Date: Mon Apr 25 19:38:49 2022 +0000
Combine functions in the command/stanza module into one function.
It is not clear why these were split out, but it probably had something to do with testing before storageList() could return NULL for an empty directory.
Also remove the tests that depended on a boolean return, which are no longer needed for coverage.
src/command/stanza/delete.c | 136 +++++++++++++++--------------------
test/src/module/command/stanzaTest.c | 4 --
2 files changed, 57 insertions(+), 83 deletions(-)
diff --git a/src/command/stanza/delete.c b/src/command/stanza/delete.c
index d5e2e7cc5..0e73509bd 100644
--- a/src/command/stanza/delete.c
+++ b/src/command/stanza/delete.c
@@ -17,96 +17,74 @@ Stanza Delete Command
#include "protocol/helper.h"
#include "storage/helper.h"
-static bool
-stanzaDelete(const Storage *storageRepoWriteStanza, const StringList *archiveList, const StringList *backupList)
+/**********************************************************************************************************************************/
+void
+cmdStanzaDelete(void)
{
- FUNCTION_TEST_BEGIN();
- FUNCTION_TEST_PARAM(STORAGE, storageRepoWriteStanza);
- FUNCTION_TEST_PARAM(STRING_LIST, archiveList);
- FUNCTION_TEST_PARAM(STRING_LIST, backupList);
- FUNCTION_TEST_END();
-
- ASSERT(storageRepoWriteStanza != NULL);
-
- bool result = false;
+ FUNCTION_LOG_VOID(logLevelDebug);
- // For most drivers, NULL indicates the directory does not exist at all. For those that do not support paths (e.g. S3) an
- // empty StringList will be returned; in such a case, the directory will attempt to be deleted (this is OK).
- if (archiveList != NULL || backupList != NULL)
+ MEM_CONTEXT_TEMP_BEGIN()
{
- bool archiveNotEmpty = (archiveList != NULL && !strLstEmpty(archiveList)) ? true : false;
- bool backupNotEmpty = (backupList != NULL && !strLstEmpty(backupList)) ? true : false;
+ const StringList *const archiveList = storageListP(storageRepo(), STORAGE_REPO_ARCHIVE_STR, .nullOnMissing = true);
+ const StringList *const backupList = storageListP(storageRepo(), STORAGE_REPO_BACKUP_STR, .nullOnMissing = true);
- // If something exists in either directory, then remove
- if (archiveNotEmpty || backupNotEmpty)
+ // For most drivers, NULL indicates the directory does not exist at all. For those that do not support paths (e.g. S3) an
+ // empty StringList will be returned; in such a case, the directory will attempt to be deleted (this is OK).
+ if (archiveList != NULL || backupList != NULL)
{
- // If the stop file does not exist, then error. This check is required even when --force is issued.
- if (!storageExistsP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza))))
- {
- THROW_FMT(
- FileMissingError, "stop file does not exist for stanza '%s'\n"
- "HINT: has the pgbackrest stop command been run on this server for this stanza?",
- strZ(cfgOptionDisplay(cfgOptStanza)));
- }
-
- // If a force has not been issued and Postgres is running, then error
- if (!cfgOptionBool(cfgOptForce) && storageExistsP(storagePg(), STRDEF(PG_FILE_POSTMTRPID)))
- {
- THROW_FMT(
- PgRunningError, PG_FILE_POSTMTRPID " exists - looks like " PG_NAME " is running. "
- "To delete stanza '%s' on %s, shut down " PG_NAME " for stanza '%s' and try again, or use --force.",
- strZ(cfgOptionDisplay(cfgOptStanza)),
- cfgOptionGroupName(cfgOptGrpRepo, cfgOptionGroupIdxDefault(cfgOptGrpRepo)),
- strZ(cfgOptionDisplay(cfgOptStanza)));
- }
+ const bool archiveNotEmpty = (archiveList != NULL && !strLstEmpty(archiveList)) ? true : false;
+ const bool backupNotEmpty = (backupList != NULL && !strLstEmpty(backupList)) ? true : false;
- // Delete the archive info files
- if (archiveNotEmpty)
+ // If something exists in either directory, then remove
+ if (archiveNotEmpty || backupNotEmpty)
{
- storageRemoveP(storageRepoWriteStanza, INFO_ARCHIVE_PATH_FILE_STR);
- storageRemoveP(storageRepoWriteStanza, INFO_ARCHIVE_PATH_FILE_COPY_STR);
+ // If the stop file does not exist, then error. This check is required even when --force is issued.
+ if (!storageExistsP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza))))
+ {
+ THROW_FMT(
+ FileMissingError, "stop file does not exist for stanza '%s'\n"
+ "HINT: has the pgbackrest stop command been run on this server for this stanza?",
+ strZ(cfgOptionDisplay(cfgOptStanza)));
+ }
+
+ // If a force has not been issued and Postgres is running, then error
+ if (!cfgOptionBool(cfgOptForce) && storageExistsP(storagePg(), STRDEF(PG_FILE_POSTMTRPID)))
+ {
+ THROW_FMT(
+ PgRunningError, PG_FILE_POSTMTRPID " exists - looks like " PG_NAME " is running. "
+ "To delete stanza '%s' on %s, shut down " PG_NAME " for stanza '%s' and try again, or use --force.",
+ strZ(cfgOptionDisplay(cfgOptStanza)),
+ cfgOptionGroupName(cfgOptGrpRepo, cfgOptionGroupIdxDefault(cfgOptGrpRepo)),
+ strZ(cfgOptionDisplay(cfgOptStanza)));
+ }
+
+ // Delete the archive info files
+ if (archiveNotEmpty)
+ {
+ storageRemoveP(storageRepoWrite(), INFO_ARCHIVE_PATH_FILE_STR);
+ storageRemoveP(storageRepoWrite(), INFO_ARCHIVE_PATH_FILE_COPY_STR);
+ }
+
+ // Delete the backup info files
+ if (backupNotEmpty)
+ {
+ storageRemoveP(storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR);
+ storageRemoveP(storageRepoWrite(), INFO_BACKUP_PATH_FILE_COPY_STR);
+ }
}
- // Delete the backup info files
- if (backupNotEmpty)
- {
- storageRemoveP(storageRepoWriteStanza, INFO_BACKUP_PATH_FILE_STR);
- storageRemoveP(storageRepoWriteStanza, INFO_BACKUP_PATH_FILE_COPY_STR);
- }
- }
-
- // Recursively remove the entire stanza repo if exists. S3 will attempt to remove even if not.
- if (archiveList != NULL)
- storagePathRemoveP(storageRepoWriteStanza, STORAGE_REPO_ARCHIVE_STR, .recurse = true);
+ // Recursively remove the entire stanza repo if exists. S3 will attempt to remove even if not.
+ if (archiveList != NULL)
+ storagePathRemoveP(storageRepoWrite(), STORAGE_REPO_ARCHIVE_STR, .recurse = true);
- if (backupList != NULL)
- storagePathRemoveP(storageRepoWriteStanza, STORAGE_REPO_BACKUP_STR, .recurse = true);
+ if (backupList != NULL)
+ storagePathRemoveP(storageRepoWrite(), STORAGE_REPO_BACKUP_STR, .recurse = true);
- // Remove the stop file - this will not error if the stop file does not exist. If the stanza directories existed but nothing
- // was in them, then no pgbackrest commands can be in progress without the info files so a stop is technically not necessary
- storageRemoveP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza)));
-
- result = true;
- }
- else
- result = true;
-
- FUNCTION_TEST_RETURN(BOOL, result);
-}
-
-/**********************************************************************************************************************************/
-void
-cmdStanzaDelete(void)
-{
- FUNCTION_LOG_VOID(logLevelDebug);
-
- MEM_CONTEXT_TEMP_BEGIN()
- {
- const Storage *storageRepoReadStanza = storageRepo();
-
- stanzaDelete(
- storageRepoWrite(), storageListP(storageRepoReadStanza, STORAGE_REPO_ARCHIVE_STR, .nullOnMissing = true),
- storageListP(storageRepoReadStanza, STORAGE_REPO_BACKUP_STR, .nullOnMissing = true));
+ // Remove the stop file - this will not error if the stop file does not exist. If the stanza directories existed but
+ // nothing was in them, then no pgbackrest commands can be in progress without the info files so a stop is technically
+ // not necessary
+ storageRemoveP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza)));
+ }
}
MEM_CONTEXT_TEMP_END();
diff --git a/test/src/module/command/stanzaTest.c b/test/src/module/command/stanzaTest.c
index a94ac78dc..becf8ce7a 100644
--- a/test/src/module/command/stanzaTest.c
+++ b/test/src/module/command/stanzaTest.c
@@ -913,10 +913,6 @@ testRun(void)
TEST_TITLE("stanza-delete - stanza already deleted");
TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - success on stanza does not exist");
- TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), NULL, NULL), true, "archiveList=NULL, backupList=NULL");
- TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), strLstNew(), NULL), true, "archiveList=0, backupList=NULL");
- TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), NULL, strLstNew()), true, "archiveList=NULL, backupList=0");
- TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), strLstNew(), strLstNew()), true, "archiveList=0, backupList=0");
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("stanza-delete - only archive exists");
[parent: 55a828f999f6]