diff --git a/src/command/archive/common.c b/src/command/archive/common.c index 1e6334e3a..6eede5a54 100644 --- a/src/command/archive/common.c +++ b/src/command/archive/common.c @@ -284,6 +284,18 @@ archiveAsyncExec(ArchiveMode archiveMode, const StringList *commandExec) FUNCTION_LOG_RETURN_VOID(); } +/**********************************************************************************************************************************/ +int +archiveIdComparator(const void *item1, const void *item2) +{ + StringList *archiveSort1 = strLstNewSplitZ(*(String **)item1, "-"); + StringList *archiveSort2 = strLstNewSplitZ(*(String **)item2, "-"); + int int1 = atoi(strZ(strLstGet(archiveSort1, 1))); + int int2 = atoi(strZ(strLstGet(archiveSort2, 1))); + + return (int1 - int2); +} + /**********************************************************************************************************************************/ bool walIsPartial(const String *walSegment) diff --git a/src/command/archive/common.h b/src/command/archive/common.h index 43cfeb9ec..42ab51824 100644 --- a/src/command/archive/common.h +++ b/src/command/archive/common.h @@ -75,6 +75,9 @@ void archiveAsyncStatusErrorWrite(ArchiveMode archiveMode, const String *walSegm // Execute the async process. This function will only return in the calling process and the implementation is platform depedent. void archiveAsyncExec(ArchiveMode archiveMode, const StringList *commandExec); +// Comparator function for sorting archive ids by the database history id (the number after the dash) e.g. 9.4-1, 10-2 +int archiveIdComparator(const void *item1, const void *item2); + // Is the segment partial? bool walIsPartial(const String *walSegment); diff --git a/src/command/expire/expire.c b/src/command/expire/expire.c index a4ec994e9..dc0f97bba 100644 --- a/src/command/expire/expire.c +++ b/src/command/expire/expire.c @@ -29,17 +29,6 @@ typedef struct ArchiveExpired String *stop; } ArchiveExpired; -static int -archiveIdComparator(const void *item1, const void *item2) -{ - StringList *archiveSort1 = strLstNewSplitZ(*(String **)item1, "-"); - StringList *archiveSort2 = strLstNewSplitZ(*(String **)item2, "-"); - int int1 = atoi(strZ(strLstGet(archiveSort1, 1))); - int int2 = atoi(strZ(strLstGet(archiveSort2, 1))); - - return (int1 - int2); -} - typedef struct ArchiveRange { const String *start; diff --git a/test/define.yaml b/test/define.yaml index 3fc7fd955..0fac11ac0 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -566,7 +566,7 @@ unit: test: # ---------------------------------------------------------------------------------------------------------------------------- - name: archive-common - total: 8 + total: 9 coverage: command/archive/common: full @@ -645,7 +645,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: expire - total: 9 + total: 8 coverage: command/expire/expire: full diff --git a/test/src/module/command/archiveCommonTest.c b/test/src/module/command/archiveCommonTest.c index dde09b9e7..21efaab45 100644 --- a/test/src/module/command/archiveCommonTest.c +++ b/test/src/module/command/archiveCommonTest.c @@ -333,5 +333,23 @@ testRun(void) "get range >= 11/1MB"); } + // ***************************************************************************************************************************** + if (testBegin("archiveIdComparator()")) + { + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("archiveId comparator sorting"); + + StringList *list = strLstComparatorSet(strLstNew(), archiveIdComparator); + + strLstAddZ(list, "10-4"); + strLstAddZ(list, "11-10"); + strLstAddZ(list, "9.6-1"); + + TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderAsc), ", "), "9.6-1, 10-4, 11-10", "sort ascending"); + + strLstAddZ(list, "9.4-2"); + TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderDesc), ", "), "11-10, 10-4, 9.4-2, 9.6-1", "sort descending"); + } + FUNCTION_HARNESS_RESULT_VOID(); } diff --git a/test/src/module/command/expireTest.c b/test/src/module/command/expireTest.c index e15df79cd..58b1f8621 100644 --- a/test/src/module/command/expireTest.c +++ b/test/src/module/command/expireTest.c @@ -2040,23 +2040,5 @@ testRun(void) harnessLogLevelReset(); } - // ***************************************************************************************************************************** - if (testBegin("archiveIdComparator()")) - { - //-------------------------------------------------------------------------------------------------------------------------- - TEST_TITLE("archiveId comparator sorting"); - - StringList *list = strLstComparatorSet(strLstNew(), archiveIdComparator); - - strLstAddZ(list, "10-4"); - strLstAddZ(list, "11-10"); - strLstAddZ(list, "9.6-1"); - - TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderAsc), ", "), "9.6-1, 10-4, 11-10", "sort ascending"); - - strLstAddZ(list, "9.4-2"); - TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderDesc), ", "), "11-10, 10-4, 9.4-2, 9.6-1", "sort descending"); - } - FUNCTION_HARNESS_RESULT_VOID(); }