0003-parse_manifest-Use-const-char.patch
text/plain
Filename: 0003-parse_manifest-Use-const-char.patch
Type: text/plain
Part: 2
Message:
jsonapi type fixups
Patch
Format: format-patch
Series: patch 0003
Subject: parse_manifest: Use const char *
| File | + | − |
|---|---|---|
| src/backend/backup/basebackup_incremental.c | 2 | 2 |
| src/bin/pg_combinebackup/load_manifest.c | 3 | 3 |
| src/bin/pg_combinebackup/load_manifest.h | 2 | 2 |
| src/bin/pg_verifybackup/pg_verifybackup.c | 8 | 8 |
| src/common/parse_manifest.c | 6 | 6 |
| src/include/common/parse_manifest.h | 3 | 3 |
From 4df85cb93e0f98e3079ec7224817fcd0f6af4d08 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 18 Jun 2024 13:42:23 +0200
Subject: [PATCH 3/3] parse_manifest: Use const char *
This adapts the manifest parsing code to take advantage of the
const-ified jsonapi.
---
src/backend/backup/basebackup_incremental.c | 4 ++--
src/bin/pg_combinebackup/load_manifest.c | 6 +++---
src/bin/pg_combinebackup/load_manifest.h | 4 ++--
src/bin/pg_verifybackup/pg_verifybackup.c | 16 ++++++++--------
src/common/parse_manifest.c | 12 ++++++------
src/include/common/parse_manifest.h | 6 +++---
6 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c
index b6cfeb6926a..a8691b680df 100644
--- a/src/backend/backup/basebackup_incremental.c
+++ b/src/backend/backup/basebackup_incremental.c
@@ -132,7 +132,7 @@ static void manifest_process_version(JsonManifestParseContext *context,
static void manifest_process_system_identifier(JsonManifestParseContext *context,
uint64 manifest_system_identifier);
static void manifest_process_file(JsonManifestParseContext *context,
- char *pathname,
+ const char *pathname,
size_t size,
pg_checksum_type checksum_type,
int checksum_length,
@@ -1043,7 +1043,7 @@ manifest_process_system_identifier(JsonManifestParseContext *context,
*/
static void
manifest_process_file(JsonManifestParseContext *context,
- char *pathname, size_t size,
+ const char *pathname, size_t size,
pg_checksum_type checksum_type,
int checksum_length,
uint8 *checksum_payload)
diff --git a/src/bin/pg_combinebackup/load_manifest.c b/src/bin/pg_combinebackup/load_manifest.c
index d857ea00066..a7bb72d16c1 100644
--- a/src/bin/pg_combinebackup/load_manifest.c
+++ b/src/bin/pg_combinebackup/load_manifest.c
@@ -46,7 +46,7 @@
*/
#define SH_PREFIX manifest_files
#define SH_ELEMENT_TYPE manifest_file
-#define SH_KEY_TYPE char *
+#define SH_KEY_TYPE const char *
#define SH_KEY pathname
#define SH_HASH_KEY(tb, key) hash_string(key)
#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
@@ -60,7 +60,7 @@ static void combinebackup_version_cb(JsonManifestParseContext *context,
static void combinebackup_system_identifier_cb(JsonManifestParseContext *context,
uint64 manifest_system_identifier);
static void combinebackup_per_file_cb(JsonManifestParseContext *context,
- char *pathname, size_t size,
+ const char *pathname, size_t size,
pg_checksum_type checksum_type,
int checksum_length,
uint8 *checksum_payload);
@@ -267,7 +267,7 @@ combinebackup_system_identifier_cb(JsonManifestParseContext *context,
*/
static void
combinebackup_per_file_cb(JsonManifestParseContext *context,
- char *pathname, size_t size,
+ const char *pathname, size_t size,
pg_checksum_type checksum_type,
int checksum_length, uint8 *checksum_payload)
{
diff --git a/src/bin/pg_combinebackup/load_manifest.h b/src/bin/pg_combinebackup/load_manifest.h
index 8a5a70e4477..a96ae12eb8e 100644
--- a/src/bin/pg_combinebackup/load_manifest.h
+++ b/src/bin/pg_combinebackup/load_manifest.h
@@ -22,7 +22,7 @@
typedef struct manifest_file
{
uint32 status; /* hash status */
- char *pathname;
+ const char *pathname;
size_t size;
pg_checksum_type checksum_type;
int checksum_length;
@@ -31,7 +31,7 @@ typedef struct manifest_file
#define SH_PREFIX manifest_files
#define SH_ELEMENT_TYPE manifest_file
-#define SH_KEY_TYPE char *
+#define SH_KEY_TYPE const char *
#define SH_SCOPE extern
#define SH_RAW_ALLOCATOR pg_malloc0
#define SH_DECLARE
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index fd610c20a65..d77e70fbe38 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -52,7 +52,7 @@
typedef struct manifest_file
{
uint32 status; /* hash status */
- char *pathname;
+ const char *pathname;
size_t size;
pg_checksum_type checksum_type;
int checksum_length;
@@ -70,7 +70,7 @@ typedef struct manifest_file
*/
#define SH_PREFIX manifest_files
#define SH_ELEMENT_TYPE manifest_file
-#define SH_KEY_TYPE char *
+#define SH_KEY_TYPE const char *
#define SH_KEY pathname
#define SH_HASH_KEY(tb, key) hash_string(key)
#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
@@ -123,7 +123,7 @@ static void verifybackup_version_cb(JsonManifestParseContext *context,
static void verifybackup_system_identifier(JsonManifestParseContext *context,
uint64 manifest_system_identifier);
static void verifybackup_per_file_cb(JsonManifestParseContext *context,
- char *pathname, size_t size,
+ const char *pathname, size_t size,
pg_checksum_type checksum_type,
int checksum_length,
uint8 *checksum_payload);
@@ -155,7 +155,7 @@ static void report_backup_error(verifier_context *context,
pg_attribute_printf(2, 3);
static void report_fatal_error(const char *pg_restrict fmt,...)
pg_attribute_printf(1, 2) pg_attribute_noreturn();
-static bool should_ignore_relpath(verifier_context *context, char *relpath);
+static bool should_ignore_relpath(verifier_context *context, const char *relpath);
static void progress_report(bool finished);
static void usage(void);
@@ -546,7 +546,7 @@ verifybackup_system_identifier(JsonManifestParseContext *context,
*/
static void
verifybackup_per_file_cb(JsonManifestParseContext *context,
- char *pathname, size_t size,
+ const char *pathname, size_t size,
pg_checksum_type checksum_type,
int checksum_length, uint8 *checksum_payload)
{
@@ -852,7 +852,7 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
char *fullpath, uint8 *buffer)
{
pg_checksum_context checksum_ctx;
- char *relpath = m->pathname;
+ const char *relpath = m->pathname;
int fd;
int rc;
size_t bytes_read = 0;
@@ -1016,13 +1016,13 @@ report_fatal_error(const char *pg_restrict fmt,...)
* "aa/bb" is not a prefix of "aa/bbb", but it is a prefix of "aa/bb/cc".
*/
static bool
-should_ignore_relpath(verifier_context *context, char *relpath)
+should_ignore_relpath(verifier_context *context, const char *relpath)
{
SimpleStringListCell *cell;
for (cell = context->ignore_list.head; cell != NULL; cell = cell->next)
{
- char *r = relpath;
+ const char *r = relpath;
char *v = cell->val;
while (*v != '\0' && *r == *v)
diff --git a/src/common/parse_manifest.c b/src/common/parse_manifest.c
index 373a4f6c00f..612e120b17a 100644
--- a/src/common/parse_manifest.c
+++ b/src/common/parse_manifest.c
@@ -112,7 +112,7 @@ static void json_manifest_finalize_system_identifier(JsonManifestParseState *par
static void json_manifest_finalize_file(JsonManifestParseState *parse);
static void json_manifest_finalize_wal_range(JsonManifestParseState *parse);
static void verify_manifest_checksum(JsonManifestParseState *parse,
- char *buffer, size_t size,
+ const char *buffer, size_t size,
pg_cryptohash_ctx *incr_ctx);
static void json_manifest_parse_failure(JsonManifestParseContext *context,
char *msg);
@@ -183,7 +183,7 @@ json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incs
void
json_parse_manifest_incremental_chunk(
- JsonManifestParseIncrementalState *incstate, char *chunk, size_t size,
+ JsonManifestParseIncrementalState *incstate, const char *chunk, size_t size,
bool is_last)
{
JsonParseErrorType res,
@@ -206,7 +206,7 @@ json_parse_manifest_incremental_chunk(
if (!is_last)
{
if (pg_cryptohash_update(incstate->manifest_ctx,
- (uint8 *) chunk, size) < 0)
+ (const uint8 *) chunk, size) < 0)
context->error_cb(context, "could not update checksum of manifest");
}
else
@@ -225,7 +225,7 @@ json_parse_manifest_incremental_chunk(
* invoked and is expected not to return.
*/
void
-json_parse_manifest(JsonManifestParseContext *context, char *buffer,
+json_parse_manifest(JsonManifestParseContext *context, const char *buffer,
size_t size)
{
JsonLexContext *lex;
@@ -810,7 +810,7 @@ json_manifest_finalize_wal_range(JsonManifestParseState *parse)
* parse incr_ctx will be NULL.
*/
static void
-verify_manifest_checksum(JsonManifestParseState *parse, char *buffer,
+verify_manifest_checksum(JsonManifestParseState *parse, const char *buffer,
size_t size, pg_cryptohash_ctx *incr_ctx)
{
JsonManifestParseContext *context = parse->context;
@@ -858,7 +858,7 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer,
{
manifest_ctx = incr_ctx;
}
- if (pg_cryptohash_update(manifest_ctx, (uint8 *) buffer, penultimate_newline + 1) < 0)
+ if (pg_cryptohash_update(manifest_ctx, (const uint8 *) buffer, penultimate_newline + 1) < 0)
context->error_cb(context, "could not update checksum of manifest");
if (pg_cryptohash_final(manifest_ctx, manifest_checksum_actual,
sizeof(manifest_checksum_actual)) < 0)
diff --git a/src/include/common/parse_manifest.h b/src/include/common/parse_manifest.h
index 2777b1e9d22..ee571a568a1 100644
--- a/src/include/common/parse_manifest.h
+++ b/src/include/common/parse_manifest.h
@@ -27,7 +27,7 @@ typedef void (*json_manifest_version_callback) (JsonManifestParseContext *,
typedef void (*json_manifest_system_identifier_callback) (JsonManifestParseContext *,
uint64 manifest_system_identifier);
typedef void (*json_manifest_per_file_callback) (JsonManifestParseContext *,
- char *pathname,
+ const char *pathname,
size_t size, pg_checksum_type checksum_type,
int checksum_length, uint8 *checksum_payload);
typedef void (*json_manifest_per_wal_range_callback) (JsonManifestParseContext *,
@@ -48,10 +48,10 @@ struct JsonManifestParseContext
};
extern void json_parse_manifest(JsonManifestParseContext *context,
- char *buffer, size_t size);
+ const char *buffer, size_t size);
extern JsonManifestParseIncrementalState *json_parse_manifest_incremental_init(JsonManifestParseContext *context);
extern void json_parse_manifest_incremental_chunk(
- JsonManifestParseIncrementalState *incstate, char *chunk, size_t size,
+ JsonManifestParseIncrementalState *incstate, const char *chunk, size_t size,
bool is_last);
extern void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate);
--
2.45.2