}
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) {
#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>
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;
+}
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 */
PAKFIRE_DIGEST_SHA512 = 2,
};
+#include <pakfire/filelist.h>
#include <pakfire/key.h>
#include <pakfire/packagelist.h>
#include <pakfire/parser.h>
// Check
-int pakfire_check(struct pakfire* pakfire);
+int pakfire_check(struct pakfire* pakfire, struct pakfire_filelist* errors);
// Sync
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;
if (r)
goto ERROR;
+ // Check files
+ r = pakfire_check_files(pakfire, db, errors);
+ if (r)
+ goto ERROR;
+
ERROR:
if (db)
pakfire_db_unref(db);