File tree Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -414,19 +414,35 @@ static int sort_chunk_cmp(const void *a_arg, const void *b_arg)
414414{
415415 struct cio_chunk * chunk_a = * (struct cio_chunk * * ) a_arg ;
416416 struct cio_chunk * chunk_b = * (struct cio_chunk * * ) b_arg ;
417- const char * p ;
417+ const char * pa , * pb ;
418+ int ra = 0 ;
419+ int rb = 0 ;
418420 struct timespec tm_a = {0 }, tm_b = {0 };
419421
420422 /* Scan Chunk A */
421- p = strchr (chunk_a -> name , '-' );
422- if (! p || parse_stamp (p + 1 , & tm_a .tv_sec , & tm_a .tv_nsec ) ! = 0 ) {
423- return -1 ;
423+ pa = strrchr (chunk_a -> name , '-' );
424+ if (pa && parse_stamp (pa + 1 , & tm_a .tv_sec , & tm_a .tv_nsec ) = = 0 ) {
425+ ra = -1 ;
424426 }
425427
426428 /* Scan Chunk B */
427- p = strchr (chunk_b -> name , '-' );
428- if (!p || parse_stamp (p + 1 , & tm_b .tv_sec , & tm_b .tv_nsec ) != 0 ) {
429- return -1 ;
429+ pb = strrchr (chunk_b -> name , '-' );
430+ if (pb && parse_stamp (pb + 1 , & tm_b .tv_sec , & tm_b .tv_nsec ) == 0 ) {
431+ rb = -1 ;
432+ }
433+
434+ /* Ensure strict ordering in presence of invalid names */
435+ if (ra != 0 || rb != 0 ) {
436+ /* valid < invalid */
437+ if (ra == 0 && rb != 0 ) {
438+ return -1 ;
439+ }
440+ /* invalid > valid */
441+ if (ra != 0 && rb == 0 ) {
442+ return 1 ;
443+ }
444+ /* both invalid: deterministic fallback */
445+ return strcmp (chunk_a -> name , chunk_b -> name );
430446 }
431447
432448 /* Compare */
You can’t perform that action at this time.
0 commit comments