]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: check: Extend to verify all files
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 13:58:57 +0000 (13:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 13:58:57 +0000 (13:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/filelist.c
src/libpakfire/include/pakfire/filelist.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c

index 49230294f26d7e052ed777689589729353d55fa0..c078572e880d8513aaf7f8fd495c9a26f155cb62 100644 (file)
@@ -1172,13 +1172,46 @@ static PyObject* Pakfire_refresh(PakfireObject* self, PyObject* args) {
 }
 
 static PyObject* Pakfire_check(PakfireObject* self) {
-       int r = pakfire_check(self->pakfire);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
+       struct pakfire_filelist* errors = NULL;
+       int r;
+
+       // Allocate a filelist for errors
+       r = pakfire_filelist_create(&errors, self->pakfire);
+       if (r)
+               goto ERROR;
+
+       // Perform check
+       r = pakfire_check(self->pakfire, errors);
+       if (r)
+               goto ERROR;
+
+       const size_t num_errors = pakfire_filelist_size(errors);
+
+       // Did we find any errors?
+       if (num_errors) {
+               PyObject* _errors = PyList_FromFileList(errors);
+               if (!_errors)
+                       goto ERROR;
+
+               pakfire_filelist_unref(errors);
+
+               // Raise CheckFileVerificationError
+               PyErr_SetObject(PyExc_CheckFileVerificationError, _errors);
+               Py_DECREF(_errors);
                return NULL;
        }
 
+       pakfire_filelist_unref(errors);
        Py_RETURN_NONE;
+
+ERROR:
+       // Cleanup
+       if (errors)
+               pakfire_filelist_unref(errors);
+
+       // Raise exception from errno
+       PyErr_SetFromErrno(PyExc_OSError);
+       return NULL;
 }
 
 static PyObject* Pakfire_sync(PakfireObject* self, PyObject* args, PyObject* kwargs) {
index 59c0a26ca86e1ac781839b2643a55e88f122c449..d0f3dcfdde7c290106cc99574ddbed4dc158aa30 100644 (file)
 
 #include <pakfire/file.h>
 #include <pakfire/filelist.h>
+#include <pakfire/i18n.h>
 #include <pakfire/logging.h>
 #include <pakfire/pakfire.h>
 #include <pakfire/private.h>
+#include <pakfire/progressbar.h>
 #include <pakfire/string.h>
 #include <pakfire/util.h>
 
@@ -517,3 +519,74 @@ int pakfire_filelist_export(struct pakfire_filelist* list, FILE* f) {
 
        return 0;
 }
+
+/*
+       Verifies all files on the filelist
+*/
+int pakfire_filelist_verify(struct pakfire_filelist* list, struct pakfire_filelist* errors) {
+       struct pakfire_progressbar* progressbar = NULL;
+       struct pakfire_file* file = NULL;
+       int r;
+
+       DEBUG(list->pakfire, "Verifying filelist (%zu file(s))...\n", list->size);
+
+       // Setup progressbar
+       r = pakfire_progressbar_create(&progressbar, NULL);
+       if (r)
+               goto ERROR;
+
+       // Add status
+       r = pakfire_progressbar_add_string(progressbar, _("Verifying Files..."));
+       if (r)
+               goto ERROR;
+
+       // Add bar
+       r = pakfire_progressbar_add_bar(progressbar);
+       if (r)
+               goto ERROR;
+
+       // Add percentage
+       r = pakfire_progressbar_add_percentage(progressbar);
+       if (r)
+               goto ERROR;
+
+       // Add ETA
+       r = pakfire_progressbar_add_eta(progressbar);
+       if (r)
+               goto ERROR;
+
+       // Start the progressbar
+       r = pakfire_progressbar_start(progressbar, list->size);
+       if (r)
+               goto ERROR;
+
+       // Iterate over the entire list
+       for (unsigned int i = 0; i < list->size; i++) {
+               file = list->elements[i];
+
+               // Verify the file
+               r = pakfire_file_verify(file);
+               if (r) {
+                       // Append the file to the error list
+                       r = pakfire_filelist_append(errors, file);
+                       if (r)
+                               goto ERROR;
+               }
+
+               // Increment progressbar
+               r = pakfire_progressbar_increment(progressbar, 1);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Finish
+       r = pakfire_progressbar_finish(progressbar);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (progressbar)
+               pakfire_progressbar_unref(progressbar);
+
+       return r;
+}
index 335bb5951ecd9a444a56519ae61a09ca0954ff1e..08f40c394f4a8882096ee12008e6d5aa04bf93d2 100644 (file)
@@ -52,6 +52,8 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root,
 int pakfire_filelist_contains(struct pakfire_filelist* list, const char* pattern);
 int pakfire_filelist_export(struct pakfire_filelist* list, FILE* f);
 
+int pakfire_filelist_verify(struct pakfire_filelist* list, struct pakfire_filelist* errors);
+
 #endif
 
 #endif /* PAKFIRE_FILELIST_H */
index 4b1d06c51af17a6de8b9508fe8223bce1c9738be..b08782871e83f83ce563640f2da1c5aba84a9546 100644 (file)
@@ -34,6 +34,7 @@ enum pakfire_digests {
        PAKFIRE_DIGEST_SHA512 = 2,
 };
 
+#include <pakfire/filelist.h>
 #include <pakfire/key.h>
 #include <pakfire/packagelist.h>
 #include <pakfire/parser.h>
@@ -113,7 +114,7 @@ int pakfire_update(struct pakfire* pakfire, int transaction_flags, int solver_fl
 
 // Check
 
-int pakfire_check(struct pakfire* pakfire);
+int pakfire_check(struct pakfire* pakfire, struct pakfire_filelist* errors);
 
 // Sync
 
index 936197bae742d99639cce3095e7aa42116307017..4dffb035b0ae10f81df18c4a225fc1c864402d7f 100644 (file)
@@ -1895,7 +1895,27 @@ static int pakfire_verify(struct pakfire* pakfire, int *changed) {
                0, changed, NULL, NULL);
 }
 
-PAKFIRE_EXPORT int pakfire_check(struct pakfire* pakfire) {
+static int pakfire_check_files(struct pakfire* pakfire,
+               struct pakfire_db* db, struct pakfire_filelist* errors) {
+       struct pakfire_filelist* filelist = NULL;
+       int r;
+
+       // Fetch the filelist
+       r = pakfire_db_filelist(db, &filelist);
+       if (r)
+               goto ERROR;
+
+       // Verify the filelist
+       r = pakfire_filelist_verify(filelist, errors);
+
+ERROR:
+       if (filelist)
+               pakfire_filelist_unref(filelist);
+
+       return r;
+}
+
+PAKFIRE_EXPORT int pakfire_check(struct pakfire* pakfire, struct pakfire_filelist* errors) {
        struct pakfire_db* db = NULL;
        int r;
 
@@ -1914,6 +1934,11 @@ PAKFIRE_EXPORT int pakfire_check(struct pakfire* pakfire) {
        if (r)
                goto ERROR;
 
+       // Check files
+       r = pakfire_check_files(pakfire, db, errors);
+       if (r)
+               goto ERROR;
+
 ERROR:
        if (db)
                pakfire_db_unref(db);