parse_manifest: Use const char *
authorPeter Eisentraut <[email protected]>
Fri, 21 Jun 2024 05:50:02 +0000 (07:50 +0200)
committerPeter Eisentraut <[email protected]>
Fri, 21 Jun 2024 05:53:30 +0000 (07:53 +0200)
This adapts the manifest parsing code to take advantage of the
const-ified jsonapi.

Reviewed-by: Andrew Dunstan <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/f732b014-f614-4600-a437-dba5a2c3738b%40eisentraut.org

src/backend/backup/basebackup_incremental.c
src/bin/pg_combinebackup/load_manifest.c
src/bin/pg_combinebackup/load_manifest.h
src/bin/pg_verifybackup/pg_verifybackup.c
src/common/parse_manifest.c
src/include/common/parse_manifest.h

index b6cfeb6926a7184c0cb5eb8bc134a03dcd997903..a8691b680dfd46cbfabe37b8388b6a577ba700e2 100644 (file)
@@ -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)
index d857ea00066196a3dd4c01c8f00d9ce1004c5526..a7bb72d16c1f26c7ad2bfb39afc426f5a00459eb 100644 (file)
@@ -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)
 {
index 8a5a70e4477cf4f877ac884b80218ade2d92683f..a96ae12eb8ed41171b132b7e71213d6c3b180e4c 100644 (file)
@@ -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
index fd610c20a654639c7365a4570d5e429962c38a81..d77e70fbe3874e2a44390b811d9e70f1e001f8e2 100644 (file)
@@ -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)
index 373a4f6c00fa94187cc2d58a8b09410ae2b8554d..612e120b17aeea3579b6346018fdf7b37487ae94 100644 (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_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)
index 2777b1e9d22c5a01a04d7aefda3d5366b96abc8a..ee571a568a19b2ca6155e8723f360bf70f883eb8 100644 (file)
@@ -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);