1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-21 20:39:46 +01:00

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

View file

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