@@ -186,7 +186,8 @@ pgFileInit(const char *path)
186186
187187 file -> is_cfs = false;
188188 file -> exists_in_prev = false; /* can change only in Incremental backup. */
189- file -> n_blocks = -1 ; /* can change only in DELTA backup. Number of blocks readed during backup */
189+ /* Number of blocks readed during backup */
190+ file -> n_blocks = BLOCKNUM_INVALID ;
190191 file -> compress_alg = NOT_DEFINED_COMPRESS ;
191192 return file ;
192193}
@@ -836,7 +837,7 @@ print_file_list(FILE *out, const parray *files, const char *root)
836837#endif
837838 fprintf (out , ",\"linked\":\"%s\"" , file -> linked );
838839
839- if (file -> n_blocks != -1 )
840+ if (file -> n_blocks != BLOCKNUM_INVALID )
840841 fprintf (out , ",\"n_blocks\":\"%i\"" , file -> n_blocks );
841842
842843 fprintf (out , "}\n" );
@@ -858,23 +859,25 @@ print_file_list(FILE *out, const parray *files, const char *root)
858859 * {"name1":"value1", "name2":"value2"}
859860 *
860861 * The value will be returned to "value_str" as string if it is not NULL. If it
861- * is NULL the value will be returned to "value_ulong" as unsigned long.
862+ * is NULL the value will be returned to "value_uint64" as int64.
863+ *
864+ * Returns true if the value was found in the line.
862865 */
863- static void
866+ static bool
864867get_control_value (const char * str , const char * name ,
865- char * value_str , uint64 * value_uint64 , bool is_mandatory )
868+ char * value_str , int64 * value_int64 , bool is_mandatory )
866869{
867870 int state = CONTROL_WAIT_NAME ;
868871 char * name_ptr = (char * ) name ;
869872 char * buf = (char * ) str ;
870- char buf_uint64 [32 ], /* Buffer for "value_uint64 " */
871- * buf_uint64_ptr = buf_uint64 ;
873+ char buf_int64 [32 ], /* Buffer for "value_int64 " */
874+ * buf_int64_ptr = buf_int64 ;
872875
873876 /* Set default values */
874877 if (value_str )
875878 * value_str = '\0' ;
876- else if (value_uint64 )
877- * value_uint64 = 0 ;
879+ else if (value_int64 )
880+ * value_int64 = 0 ;
878881
879882 while (* buf )
880883 {
@@ -909,7 +912,7 @@ get_control_value(const char *str, const char *name,
909912 if (* buf == '"' )
910913 {
911914 state = CONTROL_INVALUE ;
912- buf_uint64_ptr = buf_uint64 ;
915+ buf_int64_ptr = buf_int64 ;
913916 }
914917 else if (IsAlpha (* buf ))
915918 goto bad_format ;
@@ -922,19 +925,19 @@ get_control_value(const char *str, const char *name,
922925 {
923926 * value_str = '\0' ;
924927 }
925- else if (value_uint64 )
928+ else if (value_int64 )
926929 {
927930 /* Length of buf_uint64 should not be greater than 31 */
928- if (buf_uint64_ptr - buf_uint64 >= 32 )
931+ if (buf_int64_ptr - buf_int64 >= 32 )
929932 elog (ERROR , "field \"%s\" is out of range in the line %s of the file %s" ,
930933 name , str , DATABASE_FILE_LIST );
931934
932- * buf_uint64_ptr = '\0' ;
933- if (!parse_uint64 ( buf_uint64 , value_uint64 , 0 ))
935+ * buf_int64_ptr = '\0' ;
936+ if (!parse_int64 ( buf_int64 , value_int64 , 0 ))
934937 goto bad_format ;
935938 }
936939
937- return ;
940+ return true ;
938941 }
939942 else
940943 {
@@ -945,8 +948,8 @@ get_control_value(const char *str, const char *name,
945948 }
946949 else
947950 {
948- * buf_uint64_ptr = * buf ;
949- buf_uint64_ptr ++ ;
951+ * buf_int64_ptr = * buf ;
952+ buf_int64_ptr ++ ;
950953 }
951954 }
952955 break ;
@@ -970,11 +973,12 @@ get_control_value(const char *str, const char *name,
970973 if (is_mandatory )
971974 elog (ERROR , "field \"%s\" is not found in the line %s of the file %s" ,
972975 name , str , DATABASE_FILE_LIST );
973- return ;
976+ return false ;
974977
975978bad_format :
976979 elog (ERROR , "%s file has invalid format in line %s" ,
977980 DATABASE_FILE_LIST , str );
981+ return false; /* Make compiler happy */
978982}
979983
980984/*
@@ -1001,7 +1005,7 @@ dir_read_file_list(const char *root, const char *file_txt)
10011005 char filepath [MAXPGPATH ];
10021006 char linked [MAXPGPATH ];
10031007 char compress_alg_string [MAXPGPATH ];
1004- uint64 write_size ,
1008+ int64 write_size ,
10051009 mode , /* bit length of mode_t depends on platforms */
10061010 is_datafile ,
10071011 is_cfs ,
@@ -1016,12 +1020,7 @@ dir_read_file_list(const char *root, const char *file_txt)
10161020 get_control_value (buf , "is_datafile" , NULL , & is_datafile , true);
10171021 get_control_value (buf , "is_cfs" , NULL , & is_cfs , false);
10181022 get_control_value (buf , "crc" , NULL , & crc , true);
1019-
1020- /* optional fields */
1021- get_control_value (buf , "linked" , linked , NULL , false);
1022- get_control_value (buf , "segno" , NULL , & segno , false);
10231023 get_control_value (buf , "compress_alg" , compress_alg_string , NULL , false);
1024- get_control_value (buf , "n_blocks" , NULL , & n_blocks , false);
10251024
10261025 if (root )
10271026 join_path_components (filepath , root , path );
@@ -1036,10 +1035,19 @@ dir_read_file_list(const char *root, const char *file_txt)
10361035 file -> is_cfs = is_cfs ? true : false;
10371036 file -> crc = (pg_crc32 ) crc ;
10381037 file -> compress_alg = parse_compress_alg (compress_alg_string );
1039- if (linked [0 ])
1038+
1039+ /*
1040+ * Optional fields
1041+ */
1042+
1043+ if (get_control_value (buf , "linked" , linked , NULL , false) && linked [0 ])
10401044 file -> linked = pgut_strdup (linked );
1041- file -> segno = (int ) segno ;
1042- file -> n_blocks = (int ) n_blocks ;
1045+
1046+ if (get_control_value (buf , "segno" , NULL , & segno , false))
1047+ file -> segno = (int ) segno ;
1048+
1049+ if (get_control_value (buf , "n_blocks" , NULL , & n_blocks , false))
1050+ file -> n_blocks = (int ) n_blocks ;
10431051
10441052 parray_append (files , file );
10451053 }
0 commit comments