From 6afe99f4e37895d0e46d2ac7895d04baa000a971 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 26 Oct 2024 11:39:58 +0000 Subject: [PATCH] filelist: Avoid putting the same file on the list more than once Signed-off-by: Michael Tremer --- src/libpakfire/filelist.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index b1e6a7b93..8ce12197a 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -157,10 +157,28 @@ PAKFIRE_EXPORT struct pakfire_file* pakfire_filelist_get(struct pakfire_filelist return pakfire_file_ref(element->file); } +/* + Checks if the file is already on the list +*/ +static int pakfire_filelist_has_file(struct pakfire_filelist* list, struct pakfire_file* file) { + struct pakfire_filelist_element* e = NULL; + + TAILQ_FOREACH(e, &list->files, nodes) { + if (e->file == file) + return 1; + } + + return 0; +} + PAKFIRE_EXPORT int pakfire_filelist_add(struct pakfire_filelist* list, struct pakfire_file* file) { struct pakfire_filelist_element* element = NULL; struct pakfire_filelist_element* e = NULL; + // Do not do anything if the file is already on the list + if (pakfire_filelist_has_file(list, file)) + return 0; + // Allocate a new element element = calloc(1, sizeof *element); if (!element) { -- 2.39.5