From cd79a4fccf157712530a12e97abcab0d02acd30c Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 17 Apr 2019 16:27:39 +0200 Subject: [PATCH] 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 --- lib/filelist/image_entry_sort.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/filelist/image_entry_sort.c b/lib/filelist/image_entry_sort.c index 230b593..0480441 100644 --- a/lib/filelist/image_entry_sort.c +++ b/lib/filelist/image_entry_sort.c @@ -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;