@@ -327,6 +327,10 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
327
327
parray_qsort (files , pgFileComparePath );
328
328
}
329
329
330
+ /*
331
+ * TODO Add comment, review
332
+ * TODO if met file of unusual format throw a WARNING and don't add to list.
333
+ */
330
334
static void
331
335
dir_list_file_internal (parray * files , const char * root , bool exclude ,
332
336
bool omit_symlink , bool add_root , parray * black_list )
@@ -623,9 +627,7 @@ read_tablespace_map(parray *files, const char *backup_dir)
623
627
}
624
628
625
629
/*
626
- * Print file list.
627
- * TODO review
628
- * TODO invent more convenient format?
630
+ * Print backup content list.
629
631
*/
630
632
void
631
633
print_file_list (FILE * out , const parray * files , const char * root )
@@ -637,38 +639,33 @@ print_file_list(FILE *out, const parray *files, const char *root)
637
639
{
638
640
pgFile * file = (pgFile * ) parray_get (files , i );
639
641
char * path = file -> path ;
640
- char type ;
641
642
642
643
/* omit root directory portion */
643
644
if (root && strstr (path , root ) == path )
644
645
path = GetRelativePath (path , root );
645
646
646
- /* TODO create an enum for file mode constants */
647
- if (S_ISREG (file -> mode ) && file -> is_datafile )
648
- type = 'F' ;
649
- else if (S_ISREG (file -> mode ) && !file -> is_datafile )
650
- type = 'f' ;
651
- else if (S_ISDIR (file -> mode ))
652
- type = 'd' ;
653
- else if (S_ISLNK (file -> mode ))
654
- type = 'l' ;
655
- else
656
- type = '?' ;
647
+ fprintf (out , "{\"path\":\"%s\", \"size\":\"%lu\",\"mode\":\"%u\","
648
+ "\"is_datafile\":\"%u\" \"crc\":\"%u\"" ,
649
+ path , (unsigned long ) file -> write_size , file -> mode ,
650
+ file -> is_datafile ?1 :0 , file -> crc );
657
651
658
- fprintf (out , "%s %c %lu %u 0%o" , path , type ,
659
- (unsigned long ) file -> write_size ,
660
- file -> crc , file -> mode & (S_IRWXU | S_IRWXG | S_IRWXO ));
652
+ if (file -> is_datafile )
653
+ fprintf (out , ",\"segno\":\"%d\"" , file -> segno );
661
654
655
+ /* TODO What for do we write it to file? */
662
656
if (S_ISLNK (file -> mode ))
663
- fprintf (out , " %s " , file -> linked );
657
+ fprintf (out , ",\"linked\":\"%s\" " , file -> linked );
664
658
665
- fprintf (out , " " UINT64_FORMAT " %d\n" ,
659
+ #ifdef PGPRO_EE
660
+ fprintf (out , ",\"CFS_generation\":\"" UINT64_FORMAT "\",\"is_partial_copy\":\"%d\"" ,
666
661
file -> generation , file -> is_partial_copy );
662
+ #endif
663
+ fprintf (out , "}\n" );
667
664
}
668
665
}
669
666
670
667
/*
671
- * Construct parray of pgFile from the file list.
668
+ * Construct parray of pgFile from the backup content list.
672
669
* If root is not NULL, path will be absolute path.
673
670
*/
674
671
parray *
@@ -688,83 +685,61 @@ dir_read_file_list(const char *root, const char *file_txt)
688
685
while (fgets (buf , lengthof (buf ), fp ))
689
686
{
690
687
char path [MAXPGPATH ];
691
- char type ;
692
- int generation = -1 ;
688
+ char filepath [MAXPGPATH ];
689
+ char linked [MAXPGPATH ];
690
+ uint64 generation = -1 ;
693
691
int is_partial_copy = 0 ;
694
692
unsigned long write_size ;
695
693
pg_crc32 crc ;
696
694
unsigned int mode ; /* bit length of mode_t depends on platforms */
697
695
pgFile * file ;
696
+ char * ptr ;
697
+ unsigned int is_datafile ;
698
+ int segno = 0 ;
699
+
700
+ ptr = strstr (buf ,"path" );
701
+ sscanf (buf , "path:%s" , path );
702
+ ptr = strstr (buf ,"size" );
703
+ sscanf (buf , "size:%lu" , & write_size );
704
+ ptr = strstr (buf ,"mode" );
705
+ sscanf (buf , "mode:%u" , & mode );
706
+ ptr = strstr (buf ,"is_datafile" );
707
+ sscanf (buf , "is_datafile:%u" , & is_datafile );
708
+ ptr = strstr (buf ,"crc" );
709
+ sscanf (buf , "crc:%u" , & crc );
710
+ /* optional fields */
711
+ ptr = strstr (buf ,"linked" );
712
+ if (ptr )
713
+ sscanf (buf , "linked:%s" , linked );
714
+ ptr = strstr (buf ,"segno" );
715
+ if (ptr )
716
+ sscanf (buf , "linked:%s" , linked );
717
+ #ifdef PGPRO_EE
718
+ ptr = strstr (buf ,"CFS_generation" );
719
+ sscanf (buf , "CFS_generation:%lu" , & generation );
720
+ ptr = strstr (buf ,"is_partial_copy" );
721
+ sscanf (buf , "is_partial_copy:%d" , & is_partial_copy );
722
+ #endif
723
+ if (root )
724
+ sprintf (filepath , "%s/%s" , root , path );
725
+ else
726
+ strcpy (filepath , path );
698
727
699
- if (sscanf (buf , "%s %c %lu %u %o %d %d" ,
700
- path , & type , & write_size , & crc , & mode ,
701
- & generation , & is_partial_copy ) != 8 )
702
- {
703
- elog (ERROR , "invalid format found in \"%s\"" ,
704
- file_txt );
705
- }
706
-
707
- if (type != 'f' && type != 'F' && type != 'd' && type != 'l' )
708
- {
709
- elog (ERROR , "invalid type '%c' found in \"%s\"" ,
710
- type , file_txt );
711
- }
712
-
713
- file = (pgFile * ) pgut_malloc (sizeof (pgFile ));
714
- file -> path = pgut_malloc ((root ? strlen (root ) + 1 : 0 ) + strlen (path ) + 1 );
715
- file -> ptrack_path = NULL ;
716
- file -> segno = 0 ;
717
- file -> pagemap .bitmap = NULL ;
718
- file -> pagemap .bitmapsize = 0 ;
728
+ file = pgFileNew (filepath , false);
719
729
720
- file -> mode = mode |
721
- ((type == 'f' || type == 'F' ) ? S_IFREG :
722
- type == 'd' ? S_IFDIR : type == 'l' ? S_IFLNK : 0 );
723
- file -> generation = generation ;
724
- file -> is_partial_copy = is_partial_copy ;
725
- file -> size = 0 ;
726
- file -> read_size = 0 ;
727
730
file -> write_size = write_size ;
731
+ file -> mode = mode ;
732
+ file -> is_datafile = is_datafile ? true : false;
728
733
file -> crc = crc ;
729
- file -> is_datafile = (type == 'F' ? true : false);
730
- file -> linked = NULL ;
731
- if (root )
732
- sprintf (file -> path , "%s/%s" , root , path );
733
- else
734
- strcpy (file -> path , path );
734
+ file -> linked = NULL ; /* TODO Why don't read it? */
735
+ file -> segno = segno ;
736
+ file -> generation = generation ;
737
+ file -> is_partial_copy = is_partial_copy ;
735
738
736
739
parray_append (files , file );
737
-
738
- if (file -> is_datafile )
739
- {
740
- int find_dot ;
741
- int check_digit ;
742
- char * text_segno ;
743
- size_t path_len = strlen (file -> path );
744
- for (find_dot = path_len - 1 ; file -> path [find_dot ] != '.' && find_dot >= 0 ; find_dot -- );
745
- if (find_dot <= 0 )
746
- continue ;
747
-
748
- text_segno = file -> path + find_dot + 1 ;
749
- for (check_digit = 0 ; text_segno [check_digit ] != '\0' ; check_digit ++ )
750
- if (!isdigit (text_segno [check_digit ]))
751
- {
752
- check_digit = -1 ;
753
- break ;
754
- }
755
-
756
- if (check_digit == -1 )
757
- continue ;
758
-
759
- file -> segno = (int ) strtol (text_segno , NULL , 10 );
760
- }
761
740
}
762
741
763
742
fclose (fp );
764
-
765
- /* file.txt is sorted, so this qsort is redundant */
766
- parray_qsort (files , pgFileComparePath );
767
-
768
743
return files ;
769
744
}
770
745
0 commit comments