]> git.ipfire.org Git - pakfire.git/commitdiff
filelist: Avoid putting the same file on the list more than once
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 26 Oct 2024 11:39:58 +0000 (11:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 26 Oct 2024 11:39:58 +0000 (11:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/filelist.c

index b1e6a7b93a49dc78e49ea09b1765c3fbf7c8d453..8ce12197ae6691a934ae9838b9562723467723ce 100644 (file)
@@ -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) {