@@ -90,7 +90,7 @@ static char *pgdata_exclude_files_non_exclusive[] =
9090
9191static int BlackListCompare (const void * str1 , const void * str2 );
9292
93- static bool dir_check_file (const char * root , pgFile * file , bool exclude );
93+ static bool dir_check_file (const char * root , pgFile * file );
9494static void dir_list_file_internal (parray * files , const char * root ,
9595 pgFile * parent , bool exclude ,
9696 bool omit_symlink , parray * black_list );
@@ -401,67 +401,64 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
401401 * - datafiles
402402 */
403403static bool
404- dir_check_file (const char * root , pgFile * file , bool exclude )
404+ dir_check_file (const char * root , pgFile * file )
405405{
406406 const char * rel_path ;
407407 int i ;
408408 int sscanf_res ;
409409
410- if (exclude )
410+ /* Check if we need to exclude file by name */
411+ if (S_ISREG (file -> mode ))
411412 {
412- /* Check if we need to exclude file by name */
413- if (S_ISREG (file -> mode ))
413+ if (!exclusive_backup )
414414 {
415- if (!exclusive_backup )
416- {
417- for (i = 0 ; pgdata_exclude_files_non_exclusive [i ]; i ++ )
418- if (strcmp (file -> name ,
419- pgdata_exclude_files_non_exclusive [i ]) == 0 )
420- {
421- /* Skip */
422- elog (VERBOSE , "Excluding file: %s" , file -> name );
423- return false;
424- }
425- }
426-
427- for (i = 0 ; pgdata_exclude_files [i ]; i ++ )
428- if (strcmp (file -> name , pgdata_exclude_files [i ]) == 0 )
415+ for (i = 0 ; pgdata_exclude_files_non_exclusive [i ]; i ++ )
416+ if (strcmp (file -> name ,
417+ pgdata_exclude_files_non_exclusive [i ]) == 0 )
429418 {
430419 /* Skip */
431420 elog (VERBOSE , "Excluding file: %s" , file -> name );
432421 return false;
433422 }
434423 }
424+
425+ for (i = 0 ; pgdata_exclude_files [i ]; i ++ )
426+ if (strcmp (file -> name , pgdata_exclude_files [i ]) == 0 )
427+ {
428+ /* Skip */
429+ elog (VERBOSE , "Excluding file: %s" , file -> name );
430+ return false;
431+ }
432+ }
433+ /*
434+ * If the directory name is in the exclude list, do not list the
435+ * contents.
436+ */
437+ else if (S_ISDIR (file -> mode ))
438+ {
435439 /*
436- * If the directory name is in the exclude list, do not list the
437- * contents.
440+ * If the item in the exclude list starts with '/', compare to
441+ * the absolute path of the directory. Otherwise compare to the
442+ * directory name portion.
438443 */
439- else if ( S_ISDIR ( file -> mode ) )
444+ for ( i = 0 ; pgdata_exclude_dir [ i ]; i ++ )
440445 {
441- /*
442- * If the item in the exclude list starts with '/', compare to
443- * the absolute path of the directory. Otherwise compare to the
444- * directory name portion.
445- */
446- for (i = 0 ; pgdata_exclude_dir [i ]; i ++ )
446+ /* Full-path exclude*/
447+ if (pgdata_exclude_dir [i ][0 ] == '/' )
447448 {
448- /* Full-path exclude*/
449- if (pgdata_exclude_dir [i ][0 ] == '/' )
450- {
451- if (strcmp (file -> path , pgdata_exclude_dir [i ]) == 0 )
452- {
453- elog (VERBOSE , "Excluding directory content: %s" ,
454- file -> name );
455- return false;
456- }
457- }
458- else if (strcmp (file -> name , pgdata_exclude_dir [i ]) == 0 )
449+ if (strcmp (file -> path , pgdata_exclude_dir [i ]) == 0 )
459450 {
460451 elog (VERBOSE , "Excluding directory content: %s" ,
461452 file -> name );
462453 return false;
463454 }
464455 }
456+ else if (strcmp (file -> name , pgdata_exclude_dir [i ]) == 0 )
457+ {
458+ elog (VERBOSE , "Excluding directory content: %s" ,
459+ file -> name );
460+ return false;
461+ }
465462 }
466463 }
467464
@@ -500,27 +497,26 @@ dir_check_file(const char *root, pgFile *file, bool exclude)
500497 {
501498 file -> tblspcOid = DEFAULTTABLESPACE_OID ;
502499
503- sscanf_res = sscanf (rel_path , "base/%u/" , & (file -> dbOid ));
500+ sscanf (rel_path , "base/%u/" , & (file -> dbOid ));
504501
505502 if (S_ISDIR (file -> mode ) && strcmp (file -> name , "base" ) != 0 )
506- {
507503 file -> is_database = true;
508- sscanf (rel_path , "base/%u/" , & (file -> dbOid ));
509- }
510504 }
511505 else if (path_is_prefix_of_path (PG_TBLSPC_DIR , rel_path ))
512506 {
513507 char tmp_rel_path [MAXPGPATH ];
514508
515- sscanf_res = sscanf (rel_path , PG_TBLSPC_DIR "/%u/%s /%u/" ,
509+ sscanf_res = sscanf (rel_path , PG_TBLSPC_DIR "/%u/%[^/] /%u/" ,
516510 & (file -> tblspcOid ), tmp_rel_path ,
517511 & (file -> dbOid ));
518512
519513 if (sscanf_res == 3 && S_ISDIR (file -> mode ) &&
520514 strcmp (tmp_rel_path , TABLESPACE_VERSION_DIRECTORY ) == 0 )
521515 file -> is_database = true;
522516 }
523- else if (S_ISREG (file -> mode ) && strcmp (file -> name , "ptrack_init" ) == 0 )
517+
518+ /* Do not backup ptrack_init files */
519+ if (S_ISREG (file -> mode ) && strcmp (file -> name , "ptrack_init" ) == 0 )
524520 return false;
525521
526522 /*
@@ -642,7 +638,7 @@ dir_list_file_internal(parray *files, const char *root, pgFile *parent,
642638 if (S_ISDIR (file -> mode ))
643639 parray_append (files , file );
644640
645- if (!dir_check_file (root , file , exclude ))
641+ if (exclude && !dir_check_file (root , file ))
646642 {
647643 if (S_ISREG (file -> mode ))
648644 pgFileFree (file );
0 commit comments