@@ -758,57 +758,22 @@ dir_check_file(pgFile *file, bool backup_logs)
758
758
return CHECK_FALSE ;
759
759
else if (isdigit (file -> name [0 ]))
760
760
{
761
- char * fork_name ;
762
- int len ;
763
- char suffix [MAXPGPATH ];
761
+ set_forkname (file );
764
762
765
- fork_name = strstr (file -> name , "_" );
766
- if (fork_name )
767
- {
768
- /* Auxiliary fork of the relfile */
769
- if (strcmp (fork_name , "_vm" ) == 0 )
770
- file -> forkName = vm ;
771
-
772
- else if (strcmp (fork_name , "_fsm" ) == 0 )
773
- file -> forkName = fsm ;
774
-
775
- else if (strcmp (fork_name , "_cfm" ) == 0 )
776
- file -> forkName = cfm ;
777
-
778
- else if (strcmp (fork_name , "_ptrack" ) == 0 )
779
- file -> forkName = ptrack ;
780
-
781
- else if (strcmp (fork_name , "_init" ) == 0 )
782
- file -> forkName = init ;
783
-
784
- // extract relOid for certain forks
785
- if (file -> forkName == vm ||
786
- file -> forkName == fsm ||
787
- file -> forkName == init ||
788
- file -> forkName == cfm )
789
- {
790
- // sanity
791
- if (sscanf (file -> name , "%u_*" , & (file -> relOid )) != 1 )
792
- file -> relOid = 0 ;
793
- }
763
+ if (file -> forkName == ptrack ) /* Compatibility with left-overs from ptrack1 */
764
+ return CHECK_FALSE ;
765
+ else if (file -> forkName != none )
766
+ return CHECK_TRUE ;
794
767
795
- /* Do not backup ptrack files */
796
- if (file -> forkName == ptrack )
797
- return CHECK_FALSE ;
798
- }
799
- else
768
+ /* Set is_datafile flag */
800
769
{
770
+ char suffix [MAXFNAMELEN ];
801
771
802
- len = strlen (file -> name );
803
- /* reloid.cfm */
804
- if (len > 3 && strcmp (file -> name + len - 3 , "cfm" ) == 0 )
805
- return CHECK_TRUE ;
806
-
772
+ /* check if file is datafile */
807
773
sscanf_res = sscanf (file -> name , "%u.%d.%s" , & (file -> relOid ),
808
774
& (file -> segno ), suffix );
809
- if (sscanf_res == 0 )
810
- elog (ERROR , "Cannot parse file name \"%s\"" , file -> name );
811
- else if (sscanf_res == 1 || sscanf_res == 2 )
775
+ Assert (sscanf_res > 0 ); /* since first char is digit */
776
+ if (sscanf_res == 1 || sscanf_res == 2 )
812
777
file -> is_datafile = true;
813
778
}
814
779
}
@@ -1954,3 +1919,35 @@ pfilearray_clear_locks(parray *file_list)
1954
1919
pg_atomic_clear_flag (& file -> lock );
1955
1920
}
1956
1921
}
1922
+
1923
+ /* Set forkName if possible */
1924
+ void
1925
+ set_forkname (pgFile * file )
1926
+ {
1927
+ int name_len = strlen (file -> name );
1928
+
1929
+ /* Auxiliary fork of the relfile */
1930
+ if (name_len > 3 && strcmp (file -> name + name_len - 3 , "_vm" ) == 0 )
1931
+ file -> forkName = vm ;
1932
+
1933
+ else if (name_len > 4 && strcmp (file -> name + name_len - 4 , "_fsm" ) == 0 )
1934
+ file -> forkName = fsm ;
1935
+
1936
+ else if (name_len > 4 && strcmp (file -> name + name_len - 4 , ".cfm" ) == 0 )
1937
+ file -> forkName = cfm ;
1938
+
1939
+ else if (name_len > 5 && strcmp (file -> name + name_len - 5 , "_init" ) == 0 )
1940
+ file -> forkName = init ;
1941
+
1942
+ else if (name_len > 7 && strcmp (file -> name + name_len - 7 , "_ptrack" ) == 0 )
1943
+ file -> forkName = ptrack ;
1944
+
1945
+ // extract relOid for certain forks
1946
+
1947
+ if ((file -> forkName == vm ||
1948
+ file -> forkName == fsm ||
1949
+ file -> forkName == init ||
1950
+ file -> forkName == cfm ) &&
1951
+ (sscanf (file -> name , "%u*" , & (file -> relOid )) != 1 ))
1952
+ file -> relOid = 0 ;
1953
+ }
0 commit comments