! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
filenames with large (11 digit) numbers are sorted wrongly
Status:
RESOLVED: FIXED

Comments

Description Chris Moore 2009-05-14 10:50:30 CEST
https://photos-2.getdropbox.com/i/l/atMKvEMmqAGjfNqf47_NT6vq5pCAV7MOXJfFcAeqnnM shows an example.

a file called 22222222222 is listed before 11111111111 (both have 11 digits).

nautilus lists them in the correct order.
Comment 1 haarp 2010-01-23 21:09:49 CET
I can confirm this. The sorting order is almost completely random
Comment 2 Eric Koegel editbugs 2011-11-06 11:29:37 CET
Created attachment 3939 
Patch to fix sorting of files with large numbers in them
Comment 3 Jannis Pohlmann editbugs 2011-11-06 11:58:19 CET
The patch looks fine except that G_HAVE_GINT64 is always true, so we don't need the ifdef.
Comment 4 Eric Koegel editbugs 2011-11-06 15:03:14 CET
Created attachment 3941 
Same as pervious patch but without the #ifndef check

Fixed!
Comment 5 Jannis Pohlmann editbugs 2011-11-06 15:25:32 CET
Thanks! Applied to master and xfce-4.8:

commit 464e9a39f4490b7bd4da0ee902018c9a98950d8f
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Sun Nov 6 16:58:33 2011 +0300

    Fix sorting of filenames with large numbers (bug #5356).
    
    Change compare_by_name_using_number() to use guint64.
    
    Signed-off-by: Jannis Pohlmann <jannis@xfce.org>
Comment 6 Chris Moore 2011-11-06 19:10:48 CET
Does this really fix the problem?

It looks to me like it just changes the headline from

filenames with large (11 digit) numbers are sorted wrongly
to
filenames with large (21 digit) numbers are sorted wrongly

I think if the number is too big to handle we should fail back to sorting alphabetically rather than sorting by the number modulus some large power of 2.
Comment 7 Chris Moore 2011-11-06 20:23:32 CET
Created attachment 3942 
patch to make this work with any length numbers

This patch makes compare_by_name_using_number work for any length numbers.

It should be also be faster, since it doesn't do any arithmetic.



The comment at the end is odd:

   /* the numbers are equal, and so the higher first digit should
    * be sorted first, i.e. 'file10' before 'file010', since we
    * also sort 'file10' before 'file011'.
    */

We sort file10 before file011 because 10 is smaller than 11, not because of anything to do with higher first digits being sorted first.  I'm not sure I understand what the comment is trying to say, but a very similar argument could be made for the exact opposite ordering:

   /* the numbers are equal, and so the lower first digit should
    * be sorted first, i.e. 'file010' before 'file10', since we
    * also sort 'file010' before 'file11'.
    */

Bug #5356

Reported by:
Chris Moore
Reported on: 2009-05-14
Last modified on: 2011-11-06

People

Assignee:
Jannis Pohlmann
CC List:
2 users

Version

Attachments

Additional information