@@ -680,57 +680,22 @@ dir_check_file(pgFile *file, bool backup_logs)
680
680
return CHECK_FALSE ;
681
681
else if (isdigit (file -> name [0 ]))
682
682
{
683
- char * fork_name ;
684
- int len ;
685
- char suffix [MAXPGPATH ];
683
+ set_forkname (file );
686
684
687
- fork_name = strstr (file -> name , "_" );
688
- if (fork_name )
689
- {
690
- /* Auxiliary fork of the relfile */
691
- if (strcmp (fork_name , "_vm" ) == 0 )
692
- file -> forkName = vm ;
693
-
694
- else if (strcmp (fork_name , "_fsm" ) == 0 )
695
- file -> forkName = fsm ;
696
-
697
- else if (strcmp (fork_name , "_cfm" ) == 0 )
698
- file -> forkName = cfm ;
699
-
700
- else if (strcmp (fork_name , "_ptrack" ) == 0 )
701
- file -> forkName = ptrack ;
702
-
703
- else if (strcmp (fork_name , "_init" ) == 0 )
704
- file -> forkName = init ;
705
-
706
- // extract relOid for certain forks
707
- if (file -> forkName == vm ||
708
- file -> forkName == fsm ||
709
- file -> forkName == init ||
710
- file -> forkName == cfm )
711
- {
712
- // sanity
713
- if (sscanf (file -> name , "%u_*" , & (file -> relOid )) != 1 )
714
- file -> relOid = 0 ;
715
- }
685
+ if (file -> forkName == ptrack ) /* Compatibility with left-overs from ptrack1 */
686
+ return CHECK_FALSE ;
687
+ else if (file -> forkName != none )
688
+ return CHECK_TRUE ;
716
689
717
- /* Do not backup ptrack files */
718
- if (file -> forkName == ptrack )
719
- return CHECK_FALSE ;
720
- }
721
- else
690
+ /* Set is_datafile flag */
722
691
{
692
+ char suffix [MAXFNAMELEN ];
723
693
724
- len = strlen (file -> name );
725
- /* reloid.cfm */
726
- if (len > 3 && strcmp (file -> name + len - 3 , "cfm" ) == 0 )
727
- return CHECK_TRUE ;
728
-
694
+ /* check if file is datafile */
729
695
sscanf_res = sscanf (file -> name , "%u.%d.%s" , & (file -> relOid ),
730
696
& (file -> segno ), suffix );
731
- if (sscanf_res == 0 )
732
- elog (ERROR , "Cannot parse file name \"%s\"" , file -> name );
733
- else if (sscanf_res == 1 || sscanf_res == 2 )
697
+ Assert (sscanf_res > 0 ); /* since first char is digit */
698
+ if (sscanf_res == 1 || sscanf_res == 2 )
734
699
file -> is_datafile = true;
735
700
}
736
701
}
@@ -1869,3 +1834,35 @@ pfilearray_clear_locks(parray *file_list)
1869
1834
pg_atomic_clear_flag (& file -> lock );
1870
1835
}
1871
1836
}
1837
+
1838
+ /* Set forkName if possible */
1839
+ void
1840
+ set_forkname (pgFile * file )
1841
+ {
1842
+ int name_len = strlen (file -> name );
1843
+
1844
+ /* Auxiliary fork of the relfile */
1845
+ if (name_len > 3 && strcmp (file -> name + name_len - 3 , "_vm" ) == 0 )
1846
+ file -> forkName = vm ;
1847
+
1848
+ else if (name_len > 4 && strcmp (file -> name + name_len - 4 , "_fsm" ) == 0 )
1849
+ file -> forkName = fsm ;
1850
+
1851
+ else if (name_len > 4 && strcmp (file -> name + name_len - 4 , ".cfm" ) == 0 )
1852
+ file -> forkName = cfm ;
1853
+
1854
+ else if (name_len > 5 && strcmp (file -> name + name_len - 5 , "_init" ) == 0 )
1855
+ file -> forkName = init ;
1856
+
1857
+ else if (name_len > 7 && strcmp (file -> name + name_len - 7 , "_ptrack" ) == 0 )
1858
+ file -> forkName = ptrack ;
1859
+
1860
+ // extract relOid for certain forks
1861
+
1862
+ if ((file -> forkName == vm ||
1863
+ file -> forkName == fsm ||
1864
+ file -> forkName == init ||
1865
+ file -> forkName == cfm ) &&
1866
+ (sscanf (file -> name , "%u*" , & (file -> relOid )) != 1 ))
1867
+ file -> relOid = 0 ;
1868
+ }
0 commit comments