diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 91232a5d9..916576620 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -41,6 +41,10 @@

Add CIFS storage driver.

+ +

Make notion of current info ID in C align with Perl.

+
+

Add httpHeaderDup().

diff --git a/src/info/infoArchive.c b/src/info/infoArchive.c index 4f08cdc88..e70b646b9 100644 --- a/src/info/infoArchive.c +++ b/src/info/infoArchive.c @@ -69,7 +69,7 @@ infoArchiveNew(const Storage *storage, const String *fileName, bool ignoreMissin TRY_END(); // Store the archiveId for the current PG db-version db-id - this->archiveId = infoPgArchiveId(this->infoPg, 0); + this->archiveId = infoPgArchiveId(this->infoPg, infoPgDataCurrentId(this->infoPg)); } MEM_CONTEXT_NEW_END(); @@ -94,7 +94,7 @@ infoArchiveCheckPg(const InfoArchive *this, unsigned int pgVersion, uint64_t pgS String *errorMsg = NULL; - InfoPgData archivePg = infoPgDataCurrent(this->infoPg); + InfoPgData archivePg = infoPgData(this->infoPg, infoPgDataCurrentId(this->infoPg)); if (archivePg.version != pgVersion) { diff --git a/src/info/infoPg.c b/src/info/infoPg.c index 9b1993aa7..22dcb86b9 100644 --- a/src/info/infoPg.c +++ b/src/info/infoPg.c @@ -22,6 +22,7 @@ PostgreSQL Info Handler /*********************************************************************************************************************************** Internal constants ***********************************************************************************************************************************/ +STRING_STATIC(INFO_SECTION_DB_STR, "db"); STRING_STATIC(INFO_SECTION_DB_HISTORY_STR, "db:history"); STRING_EXTERN(INFO_KEY_DB_ID_STR, INFO_KEY_DB_ID); @@ -37,6 +38,7 @@ struct InfoPg { MemContext *memContext; // Context that contains the infoPg List *history; // A list of InfoPgData + unsigned int historyCurrent; // Index of the current history item Info *info; // Info contents }; @@ -76,12 +78,16 @@ infoPgNew(const Storage *storage, const String *fileName, InfoPgType type, Ciphe MEM_CONTEXT_TEMP_BEGIN() { const Ini *infoPgIni = infoIni(this->info); + const String *pgSection = INFO_SECTION_DB_STR; const String *pgHistorySection = INFO_SECTION_DB_HISTORY_STR; const StringList *pgHistoryKey = iniSectionKeyList(infoPgIni, pgHistorySection); const Variant *idKey = varNewStr(INFO_KEY_DB_ID_STR); const Variant *systemIdKey = varNewStr(INFO_KEY_DB_SYSTEM_ID_STR); const Variant *versionKey = varNewStr(INFO_KEY_DB_VERSION_STR); + // Get the current history id + unsigned int pgId = (unsigned int)varUInt64Force(iniGet(infoPgIni, pgSection, varStr(idKey))); + // History must include at least one item or the file is corrupt ASSERT(strLstSize(pgHistoryKey) > 0); @@ -104,6 +110,10 @@ infoPgNew(const Storage *storage, const String *fileName, InfoPgType type, Ciphe .systemId = varUInt64Force(kvGet(pgDataKv, type == infoPgArchive ? idKey : systemIdKey)), }; + // Set index if this is the current history item + if (infoPgData.id == pgId) + this->historyCurrent = lstSize(this->history); + // Get values that are only in backup and manifest files. These are really vestigial since stanza-create verifies // the control and catalog versions so there is no good reason to store them. However, for backward compatability // we must write them at least, even if we give up reading them. @@ -210,7 +220,22 @@ infoPgDataCurrent(const InfoPg *this) ASSERT(this != NULL); - FUNCTION_LOG_RETURN(INFO_PG_DATA, infoPgData(this, 0)); + FUNCTION_LOG_RETURN(INFO_PG_DATA, infoPgData(this, infoPgDataCurrentId(this))); +} + +/*********************************************************************************************************************************** +Return the current history index +***********************************************************************************************************************************/ +unsigned int +infoPgDataCurrentId(const InfoPg *this) +{ + FUNCTION_LOG_BEGIN(logLevelDebug); + FUNCTION_LOG_PARAM(INFO_PG, this); + FUNCTION_LOG_END(); + + ASSERT(this != NULL); + + FUNCTION_LOG_RETURN(UINT, this->historyCurrent); } /*********************************************************************************************************************************** diff --git a/src/info/infoPg.h b/src/info/infoPg.h index 462a0be7c..17a0c9dc3 100644 --- a/src/info/infoPg.h +++ b/src/info/infoPg.h @@ -60,6 +60,7 @@ String *infoPgArchiveId(const InfoPg *this, unsigned int pgDataIdx); const String *infoPgCipherPass(const InfoPg *this); InfoPgData infoPgData(const InfoPg *this, unsigned int pgDataIdx); InfoPgData infoPgDataCurrent(const InfoPg *this); +unsigned int infoPgDataCurrentId(const InfoPg *this); unsigned int infoPgDataTotal(const InfoPg *this); Ini *infoPgIni(const InfoPg *this); diff --git a/test/src/module/command/archiveGetTest.c b/test/src/module/command/archiveGetTest.c index 173f25add..e2a1d3274 100644 --- a/test/src/module/command/archiveGetTest.c +++ b/test/src/module/command/archiveGetTest.c @@ -55,10 +55,13 @@ testRun(void) storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")), bufNewZ( "[backrest]\n" - "backrest-checksum=\"0a415a03fa3faccb4ac171759895478469e9e19e\"\n" + "backrest-checksum=\"806471e1481804dc3ddf8dc6f1da7c34939420a8\"\n" "backrest-format=5\n" "backrest-version=\"2.06\"\n" "\n" + "[db]\n" + "db-id=1\n" + "\n" "[db:history]\n" "1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n")); @@ -72,10 +75,13 @@ testRun(void) storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")), bufNewZ( "[backrest]\n" - "backrest-checksum=\"f7617b5c4c9f212f40b9bc3d8ec7f97edbbf96af\"\n" + "backrest-checksum=\"4120e2a5c3918a480af951fb99bee7dc091f080a\"\n" "backrest-format=5\n" "backrest-version=\"2.06\"\n" "\n" + "[db]\n" + "db-id=3\n" + "\n" "[db:history]\n" "1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n" "2={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n" @@ -147,10 +153,13 @@ testRun(void) storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")), bufNewZ( "[backrest]\n" - "backrest-checksum=\"8a041a4128eaa2c08a23dd1f04934627795946ff\"\n" + "backrest-checksum=\"bf9d69c6131e906898511432b4445335f377b12b\"\n" "backrest-format=5\n" "backrest-version=\"2.06\"\n" "\n" + "[db]\n" + "db-id=1\n" + "\n" "[db:history]\n" "1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}")); @@ -201,13 +210,16 @@ testRun(void) infoWrite, bufNewZ( "[backrest]\n" - "backrest-checksum=\"60bfcb0a5a2c91d203c11d7f1924e99dcdfa0b80\"\n" + "backrest-checksum=\"5e4bf8cafff30b488c01574411e858c7866df4a2\"\n" "backrest-format=5\n" "backrest-version=\"2.06\"\n" "\n" "[cipher]\n" "cipher-pass=\"worstpassphraseever\"\n" "\n" + "[db]\n" + "db-id=1\n" + "\n" "[db:history]\n" "1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}")); @@ -362,10 +374,13 @@ testRun(void) storageNewWriteNP(storageTest, strNew("repo/archive/test2/archive.info")), bufNewZ( "[backrest]\n" - "backrest-checksum=\"d962d8d7311d0ae5dc0b05892c15cfa2009d051e\"\n" + "backrest-checksum=\"398aa38312ce69e3625b2ecfb4dfc6387e5ce7d3\"\n" "backrest-format=5\n" "backrest-version=\"2.11\"\n" "\n" + "[db]\n" + "db-id=1\n" + "\n" "[db:history]\n" "1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n"));