diff options
Diffstat (limited to 'src/backend/replication/backup_manifest.c')
-rw-r--r-- | src/backend/replication/backup_manifest.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/backend/replication/backup_manifest.c b/src/backend/replication/backup_manifest.c index bab5e2f53b0..c3f339c5563 100644 --- a/src/backend/replication/backup_manifest.c +++ b/src/backend/replication/backup_manifest.c @@ -65,7 +65,9 @@ InitializeBackupManifest(backup_manifest_info *manifest, else { manifest->buffile = BufFileCreateTemp(false); - pg_sha256_init(&manifest->manifest_ctx); + manifest->manifest_ctx = pg_cryptohash_create(PG_SHA256); + if (pg_cryptohash_init(manifest->manifest_ctx) < 0) + elog(ERROR, "failed to initialize checksum of backup manifest"); } manifest->manifest_size = UINT64CONST(0); @@ -80,6 +82,16 @@ InitializeBackupManifest(backup_manifest_info *manifest, } /* + * Free resources assigned to a backup manifest constructed. + */ +void +FreeBackupManifest(backup_manifest_info *manifest) +{ + pg_cryptohash_free(manifest->manifest_ctx); + manifest->manifest_ctx = NULL; +} + +/* * Add an entry to the backup manifest for a file. */ void @@ -166,6 +178,9 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid, int checksumlen; checksumlen = pg_checksum_final(checksum_ctx, checksumbuf); + if (checksumlen < 0) + elog(ERROR, "could not finalize checksum of file \"%s\"", + pathname); appendStringInfo(&buf, ", \"Checksum-Algorithm\": \"%s\", \"Checksum\": \"", @@ -310,7 +325,8 @@ SendBackupManifest(backup_manifest_info *manifest) * twice. */ manifest->still_checksumming = false; - pg_sha256_final(&manifest->manifest_ctx, checksumbuf); + if (pg_cryptohash_final(manifest->manifest_ctx, checksumbuf) < 0) + elog(ERROR, "failed to finalize checksum of backup manifest"); AppendStringToManifest(manifest, "\"Manifest-Checksum\": \""); hex_encode((char *) checksumbuf, sizeof checksumbuf, checksumstringbuf); checksumstringbuf[PG_SHA256_DIGEST_STRING_LENGTH - 1] = '\0'; @@ -373,7 +389,10 @@ AppendStringToManifest(backup_manifest_info *manifest, char *s) Assert(manifest != NULL); if (manifest->still_checksumming) - pg_sha256_update(&manifest->manifest_ctx, (uint8 *) s, len); + { + if (pg_cryptohash_update(manifest->manifest_ctx, (uint8 *) s, len) < 0) + elog(ERROR, "failed to update checksum of backup manifest"); + } BufFileWrite(manifest->buffile, s, len); manifest->manifest_size += len; } |