From aa44824788582cd3278ff74a60dfb276cf1aebfc Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 9 Dec 2016 11:14:07 -0500 Subject: filelist_sort: check if filelist is presorted Signed-off-by: Andrew Gregory Signed-off-by: Allan McRae --- lib/libalpm/filelist.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c index 46fb4b8d..97f639a9 100644 --- a/lib/libalpm/filelist.c +++ b/lib/libalpm/filelist.c @@ -135,8 +135,15 @@ alpm_file_t SYMEXPORT *alpm_filelist_contains(alpm_filelist_t *filelist, void _alpm_filelist_sort(alpm_filelist_t *filelist) { - qsort(filelist->files, filelist->count, - sizeof(alpm_file_t), _alpm_files_cmp); + size_t i; + for(i = 1; i < filelist->count; i++) { + if(strcmp(filelist->files[i - 1].name, filelist->files[i].name) > 0) { + /* filelist is not pre-sorted */ + qsort(filelist->files, filelist->count, + sizeof(alpm_file_t), _alpm_files_cmp); + return; + } + } } /* vim: set noet: */ -- cgit v1.2.3-24-g4f1b