[pacman-dev] [PATCH 4/5] add _alpm_filelist_sort
Andrew Gregory
andrew.gregory.8 at gmail.com
Fri Dec 9 16:14:06 UTC 2016
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
lib/libalpm/be_local.c | 4 +---
lib/libalpm/be_package.c | 3 +--
lib/libalpm/be_sync.c | 3 +--
lib/libalpm/filelist.c | 8 +++++++-
lib/libalpm/filelist.h | 2 +-
5 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 15b271f..ad8b245 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -817,14 +817,12 @@ static int local_db_read(alpm_pkg_t *info, int inforeq)
if(newfiles != NULL) {
files = newfiles;
}
-
- /* make sure the list is sorted */
- qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp);
} else {
FREE(files);
}
info->files.count = files_count;
info->files.files = files;
+ _alpm_filelist_sort(&info->files);
continue;
nomem:
while(files_count > 0) {
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index b7c54fa..926edbf 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -676,8 +676,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
_alpm_log(handle, ALPM_LOG_DEBUG,
"sorting package filelist for %s\n", pkgfile);
- qsort(newpkg->files.files, newpkg->files.count,
- sizeof(alpm_file_t), _alpm_files_cmp);
+ _alpm_filelist_sort(&newpkg->files);
}
newpkg->infolevel |= INFRQ_FILES;
}
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 7774975..edf4746 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -735,13 +735,12 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
/* attempt to hand back any memory we don't need */
if(files_count > 0) {
files = realloc(files, sizeof(alpm_file_t) * files_count);
- /* make sure the list is sorted */
- qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp);
} else {
FREE(files);
}
pkg->files.count = files_count;
pkg->files.files = files;
+ _alpm_filelist_sort(&pkg->files);
}
}
if(ret != ARCHIVE_EOF) {
diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c
index 5783373..318b2b7 100644
--- a/lib/libalpm/filelist.c
+++ b/lib/libalpm/filelist.c
@@ -111,7 +111,7 @@ alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
/* Helper function for comparing files list entries
*/
-int _alpm_files_cmp(const void *f1, const void *f2)
+static int _alpm_files_cmp(const void *f1, const void *f2)
{
const alpm_file_t *file1 = f1;
const alpm_file_t *file2 = f2;
@@ -133,4 +133,10 @@ alpm_file_t SYMEXPORT *alpm_filelist_contains(alpm_filelist_t *filelist,
sizeof(alpm_file_t), _alpm_files_cmp);
}
+void _alpm_filelist_sort(alpm_filelist_t *filelist)
+{
+ qsort(filelist->files, filelist->count,
+ sizeof(alpm_file_t), _alpm_files_cmp);
+}
+
/* vim: set noet: */
diff --git a/lib/libalpm/filelist.h b/lib/libalpm/filelist.h
index a74bdea..fa6d5c5 100644
--- a/lib/libalpm/filelist.h
+++ b/lib/libalpm/filelist.h
@@ -27,7 +27,7 @@ alpm_list_t *_alpm_filelist_difference(alpm_filelist_t *filesA,
alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
alpm_filelist_t *filesB);
-int _alpm_files_cmp(const void *f1, const void *f2);
+void _alpm_filelist_sort(alpm_filelist_t *filelist);
#endif /* ALPM_FILELIST_H */
--
2.10.2
More information about the pacman-dev
mailing list