1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

parse_manifest: Use const char *

This adapts the manifest parsing code to take advantage of the
const-ified jsonapi.

Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://www.postgresql.org/message-id/flat/f732b014-f614-4600-a437-dba5a2c3738b%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2024-06-21 07:50:02 +02:00
parent 15cd9a3881
commit 02bbc3c83a
6 changed files with 24 additions and 24 deletions

View File

@ -132,7 +132,7 @@ static void manifest_process_version(JsonManifestParseContext *context,
static void manifest_process_system_identifier(JsonManifestParseContext *context, static void manifest_process_system_identifier(JsonManifestParseContext *context,
uint64 manifest_system_identifier); uint64 manifest_system_identifier);
static void manifest_process_file(JsonManifestParseContext *context, static void manifest_process_file(JsonManifestParseContext *context,
char *pathname, const char *pathname,
size_t size, size_t size,
pg_checksum_type checksum_type, pg_checksum_type checksum_type,
int checksum_length, int checksum_length,
@ -1043,7 +1043,7 @@ manifest_process_system_identifier(JsonManifestParseContext *context,
*/ */
static void static void
manifest_process_file(JsonManifestParseContext *context, manifest_process_file(JsonManifestParseContext *context,
char *pathname, size_t size, const char *pathname, size_t size,
pg_checksum_type checksum_type, pg_checksum_type checksum_type,
int checksum_length, int checksum_length,
uint8 *checksum_payload) uint8 *checksum_payload)

View File

@ -46,7 +46,7 @@
*/ */
#define SH_PREFIX manifest_files #define SH_PREFIX manifest_files
#define SH_ELEMENT_TYPE manifest_file #define SH_ELEMENT_TYPE manifest_file
#define SH_KEY_TYPE char * #define SH_KEY_TYPE const char *
#define SH_KEY pathname #define SH_KEY pathname
#define SH_HASH_KEY(tb, key) hash_string(key) #define SH_HASH_KEY(tb, key) hash_string(key)
#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0) #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, static void combinebackup_system_identifier_cb(JsonManifestParseContext *context,
uint64 manifest_system_identifier); uint64 manifest_system_identifier);
static void combinebackup_per_file_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, pg_checksum_type checksum_type,
int checksum_length, int checksum_length,
uint8 *checksum_payload); uint8 *checksum_payload);
@ -267,7 +267,7 @@ combinebackup_system_identifier_cb(JsonManifestParseContext *context,
*/ */
static void static void
combinebackup_per_file_cb(JsonManifestParseContext *context, combinebackup_per_file_cb(JsonManifestParseContext *context,
char *pathname, size_t size, const char *pathname, size_t size,
pg_checksum_type checksum_type, pg_checksum_type checksum_type,
int checksum_length, uint8 *checksum_payload) int checksum_length, uint8 *checksum_payload)
{ {

View File

@ -22,7 +22,7 @@
typedef struct manifest_file typedef struct manifest_file
{ {
uint32 status; /* hash status */ uint32 status; /* hash status */
char *pathname; const char *pathname;
size_t size; size_t size;
pg_checksum_type checksum_type; pg_checksum_type checksum_type;
int checksum_length; int checksum_length;
@ -31,7 +31,7 @@ typedef struct manifest_file
#define SH_PREFIX manifest_files #define SH_PREFIX manifest_files
#define SH_ELEMENT_TYPE manifest_file #define SH_ELEMENT_TYPE manifest_file
#define SH_KEY_TYPE char * #define SH_KEY_TYPE const char *
#define SH_SCOPE extern #define SH_SCOPE extern
#define SH_RAW_ALLOCATOR pg_malloc0 #define SH_RAW_ALLOCATOR pg_malloc0
#define SH_DECLARE #define SH_DECLARE

View File

@ -52,7 +52,7 @@
typedef struct manifest_file typedef struct manifest_file
{ {
uint32 status; /* hash status */ uint32 status; /* hash status */
char *pathname; const char *pathname;
size_t size; size_t size;
pg_checksum_type checksum_type; pg_checksum_type checksum_type;
int checksum_length; int checksum_length;
@ -70,7 +70,7 @@ typedef struct manifest_file
*/ */
#define SH_PREFIX manifest_files #define SH_PREFIX manifest_files
#define SH_ELEMENT_TYPE manifest_file #define SH_ELEMENT_TYPE manifest_file
#define SH_KEY_TYPE char * #define SH_KEY_TYPE const char *
#define SH_KEY pathname #define SH_KEY pathname
#define SH_HASH_KEY(tb, key) hash_string(key) #define SH_HASH_KEY(tb, key) hash_string(key)
#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0) #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, static void verifybackup_system_identifier(JsonManifestParseContext *context,
uint64 manifest_system_identifier); uint64 manifest_system_identifier);
static void verifybackup_per_file_cb(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, pg_checksum_type checksum_type,
int checksum_length, int checksum_length,
uint8 *checksum_payload); uint8 *checksum_payload);
@ -155,7 +155,7 @@ static void report_backup_error(verifier_context *context,
pg_attribute_printf(2, 3); pg_attribute_printf(2, 3);
static void report_fatal_error(const char *pg_restrict fmt,...) static void report_fatal_error(const char *pg_restrict fmt,...)
pg_attribute_printf(1, 2) pg_attribute_noreturn(); 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 progress_report(bool finished);
static void usage(void); static void usage(void);
@ -546,7 +546,7 @@ verifybackup_system_identifier(JsonManifestParseContext *context,
*/ */
static void static void
verifybackup_per_file_cb(JsonManifestParseContext *context, verifybackup_per_file_cb(JsonManifestParseContext *context,
char *pathname, size_t size, const char *pathname, size_t size,
pg_checksum_type checksum_type, pg_checksum_type checksum_type,
int checksum_length, uint8 *checksum_payload) int checksum_length, uint8 *checksum_payload)
{ {
@ -852,7 +852,7 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
char *fullpath, uint8 *buffer) char *fullpath, uint8 *buffer)
{ {
pg_checksum_context checksum_ctx; pg_checksum_context checksum_ctx;
char *relpath = m->pathname; const char *relpath = m->pathname;
int fd; int fd;
int rc; int rc;
size_t bytes_read = 0; 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". * "aa/bb" is not a prefix of "aa/bbb", but it is a prefix of "aa/bb/cc".
*/ */
static bool static bool
should_ignore_relpath(verifier_context *context, char *relpath) should_ignore_relpath(verifier_context *context, const char *relpath)
{ {
SimpleStringListCell *cell; SimpleStringListCell *cell;
for (cell = context->ignore_list.head; cell != NULL; cell = cell->next) for (cell = context->ignore_list.head; cell != NULL; cell = cell->next)
{ {
char *r = relpath; const char *r = relpath;
char *v = cell->val; char *v = cell->val;
while (*v != '\0' && *r == *v) while (*v != '\0' && *r == *v)

View File

@ -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_file(JsonManifestParseState *parse);
static void json_manifest_finalize_wal_range(JsonManifestParseState *parse); static void json_manifest_finalize_wal_range(JsonManifestParseState *parse);
static void verify_manifest_checksum(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); pg_cryptohash_ctx *incr_ctx);
static void json_manifest_parse_failure(JsonManifestParseContext *context, static void json_manifest_parse_failure(JsonManifestParseContext *context,
char *msg); char *msg);
@ -183,7 +183,7 @@ json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incs
void void
json_parse_manifest_incremental_chunk( json_parse_manifest_incremental_chunk(
JsonManifestParseIncrementalState *incstate, char *chunk, size_t size, JsonManifestParseIncrementalState *incstate, const char *chunk, size_t size,
bool is_last) bool is_last)
{ {
JsonParseErrorType res, JsonParseErrorType res,
@ -206,7 +206,7 @@ json_parse_manifest_incremental_chunk(
if (!is_last) if (!is_last)
{ {
if (pg_cryptohash_update(incstate->manifest_ctx, 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"); context->error_cb(context, "could not update checksum of manifest");
} }
else else
@ -225,7 +225,7 @@ json_parse_manifest_incremental_chunk(
* invoked and is expected not to return. * invoked and is expected not to return.
*/ */
void void
json_parse_manifest(JsonManifestParseContext *context, char *buffer, json_parse_manifest(JsonManifestParseContext *context, const char *buffer,
size_t size) size_t size)
{ {
JsonLexContext *lex; JsonLexContext *lex;
@ -810,7 +810,7 @@ json_manifest_finalize_wal_range(JsonManifestParseState *parse)
* parse incr_ctx will be NULL. * parse incr_ctx will be NULL.
*/ */
static void 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) size_t size, pg_cryptohash_ctx *incr_ctx)
{ {
JsonManifestParseContext *context = parse->context; JsonManifestParseContext *context = parse->context;
@ -858,7 +858,7 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer,
{ {
manifest_ctx = incr_ctx; 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"); context->error_cb(context, "could not update checksum of manifest");
if (pg_cryptohash_final(manifest_ctx, manifest_checksum_actual, if (pg_cryptohash_final(manifest_ctx, manifest_checksum_actual,
sizeof(manifest_checksum_actual)) < 0) sizeof(manifest_checksum_actual)) < 0)

View File

@ -27,7 +27,7 @@ typedef void (*json_manifest_version_callback) (JsonManifestParseContext *,
typedef void (*json_manifest_system_identifier_callback) (JsonManifestParseContext *, typedef void (*json_manifest_system_identifier_callback) (JsonManifestParseContext *,
uint64 manifest_system_identifier); uint64 manifest_system_identifier);
typedef void (*json_manifest_per_file_callback) (JsonManifestParseContext *, typedef void (*json_manifest_per_file_callback) (JsonManifestParseContext *,
char *pathname, const char *pathname,
size_t size, pg_checksum_type checksum_type, size_t size, pg_checksum_type checksum_type,
int checksum_length, uint8 *checksum_payload); int checksum_length, uint8 *checksum_payload);
typedef void (*json_manifest_per_wal_range_callback) (JsonManifestParseContext *, typedef void (*json_manifest_per_wal_range_callback) (JsonManifestParseContext *,
@ -48,10 +48,10 @@ struct JsonManifestParseContext
}; };
extern void json_parse_manifest(JsonManifestParseContext *context, 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 JsonManifestParseIncrementalState *json_parse_manifest_incremental_init(JsonManifestParseContext *context);
extern void json_parse_manifest_incremental_chunk( 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); bool is_last);
extern void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate); extern void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate);