@@ -566,31 +566,29 @@ pgstat_reset_remove_files(const char *directory)
566
566
dir = AllocateDir (directory );
567
567
while ((entry = ReadDir (dir ,directory ))!= NULL )
568
568
{
569
- int nitems ;
570
- Oid tmp_oid ;
571
- char tmp_type [8 ];
572
- char tmp_rest [2 ];
573
-
574
- if (strncmp (entry -> d_name ,"." ,2 )== 0 ||
575
- strncmp (entry -> d_name ,".." ,3 )== 0 )
576
- continue ;
569
+ int nchars ;
570
+ Oid tmp_oid ;
577
571
578
572
/*
579
573
* Skip directory entries that don't match the file names we write.
580
574
* See get_dbstat_filename for the database-specific pattern.
581
575
*/
582
- nitems = sscanf ( entry -> d_name ,"db_%u.%5s%1s" ,
583
- & tmp_oid , tmp_type , tmp_rest ) ;
584
- if ( nitems != 2 )
576
+ if ( strncmp ( entry -> d_name ,"global." , 7 ) == 0 )
577
+ nchars = 7 ;
578
+ else
585
579
{
586
- nitems = sscanf (entry -> d_name ,"global.%5s%1s" ,
587
- tmp_type ,tmp_rest );
588
- if (nitems != 1 )
580
+ nchars = 0 ;
581
+ (void )sscanf (entry -> d_name ,"db_%u.%n" ,
582
+ & tmp_oid ,& nchars );
583
+ if (nchars <=0 )
584
+ continue ;
585
+ /* %u allows leading whitespace, so reject that */
586
+ if (strchr ("0123456789" ,entry -> d_name [3 ])== NULL )
589
587
continue ;
590
588
}
591
589
592
- if (strncmp ( tmp_type ,"tmp" , 4 )!= 0 &&
593
- strncmp ( tmp_type ,"stat" , 5 )!= 0 )
590
+ if (strcmp ( entry -> d_name + nchars ,"tmp" )!= 0 &&
591
+ strcmp ( entry -> d_name + nchars ,"stat" )!= 0 )
594
592
continue ;
595
593
596
594
snprintf (fname ,MAXPGPATH ,"%s/%s" ,directory ,