make file list sorting more robust

If entries are sorted by length and some have the same length, sort
them asciibetically.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-04-17 16:27:39 +02:00
parent eadeee25d9
commit cd79a4fccf
1 changed files with 4 additions and 1 deletions

View File

@ -6,6 +6,8 @@
static int compare_ent(image_entry_t *a, image_entry_t *b)
{
int diff;
/* directories < .. < symlinks < devices < .. < files */
switch (a->mode & S_IFMT) {
case S_IFDIR:
@ -31,7 +33,8 @@ static int compare_ent(image_entry_t *a, image_entry_t *b)
return -1;
}
out_len:
return (int)strlen(a->name) - (int)strlen(b->name);
diff = (int)strlen(a->name) - (int)strlen(b->name);
return diff ? diff : strcmp(a->name, b->name);
out_fsize:
if (a->data.file.size > b->data.file.size)
return 1;