#include <stdlib.h>
#include <sys/queue.h>
+// libarchive
#include <archive.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
+#include <pakfire/ctx.h>
#include <pakfire/file.h>
#include <pakfire/filelist.h>
#include <pakfire/i18n.h>
};
PAKFIRE_EXPORT int pakfire_filelist_create(struct pakfire_filelist** list, struct pakfire* pakfire) {
- struct pakfire_filelist* l = calloc(1, sizeof(*l));
+ struct pakfire_filelist* l = NULL;
+
+ // Allocate a new object
+ l = calloc(1, sizeof(*l));
if (!l)
- return -ENOMEM;
+ return -errno;
// Store a reference to the context
l->ctx = pakfire_ctx(pakfire);
+ // Store a reference to Pakfire
l->pakfire = pakfire_ref(pakfire);
+
+ // Initialize the reference counter
l->nrefs = 1;
// Initialise files
TAILQ_INIT(&l->files);
+ // Return the pointer
*list = l;
+
return 0;
}
static void pakfire_filelist_free(struct pakfire_filelist* list) {
pakfire_filelist_clear(list);
- pakfire_unref(list->pakfire);
+ if (list->pakfire)
+ pakfire_unref(list->pakfire);
if (list->ctx)
pakfire_ctx_unref(list->ctx);
free(list);
// Allocate a new element
element = calloc(1, sizeof *element);
if (!element) {
- ERROR(list->pakfire, "Could not allocate a new filelist element: %m\n");
+ CTX_ERROR(list->ctx, "Could not allocate a new filelist element: %m\n");
return 1;
}
return 1;
}
- DEBUG(list->pakfire, "Scanning %s...\n", root);
+ CTX_DEBUG(list->ctx, "Scanning %s...\n", root);
if (includes) {
- DEBUG(list->pakfire, " Includes:\n");
+ CTX_DEBUG(list->ctx, " Includes:\n");
for (const char** include = includes; *include; include++)
- DEBUG(list->pakfire, " %s\n", *include);
+ CTX_DEBUG(list->ctx, " %s\n", *include);
}
if (excludes) {
- DEBUG(list->pakfire, " Excludes:\n");
+ CTX_DEBUG(list->ctx, " Excludes:\n");
for (const char** exclude = excludes; *exclude; exclude++)
- DEBUG(list->pakfire, " %s\n", *exclude);
+ CTX_DEBUG(list->ctx, " %s\n", *exclude);
}
// Check if the path exists
if (!pakfire_path_exists(root)) {
- DEBUG(list->pakfire, "Path to scan (%s) does not exist\n", root);
+ CTX_DEBUG(list->ctx, "Path to scan (%s) does not exist\n", root);
r = 0;
goto ERROR;
}
// Start reading from here
r = archive_read_disk_open(reader, root);
if (r) {
- ERROR(list->pakfire, "Could not open %s: %s\n", root,
- archive_error_string(reader));
+ CTX_ERROR(list->ctx, "Could not open %s: %s\n",
+ root, archive_error_string(reader));
goto ERROR;
}
r = archive_read_disk_set_metadata_filter_callback(reader,
pakfire_filelist_scan_filter, &matches);
if (r) {
- ERROR(list->pakfire, "Could not set filter callback: %s\n",
+ CTX_ERROR(list->ctx, "Could not set filter callback: %s\n",
archive_error_string(reader));
goto ERROR;
}
// Raise any other errors
default:
- ERROR(list->pakfire, "Could not read next file: %s\n",
+ CTX_ERROR(list->ctx, "Could not read next file: %s\n",
archive_error_string(reader));
goto ERROR;
}
struct pakfire* pakfire, struct pakfire_file* file, void* data) {
int* flags = (int*)data;
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
char* s = pakfire_file_dump(file, *flags);
if (s) {
- INFO(pakfire, "%s\n", s);
+ CTX_INFO(ctx, "%s\n", s);
free(s);
}
+ pakfire_ctx_unref(ctx);
+
return 0;
}
const size_t length = pakfire_filelist_length(list);
- DEBUG(list->pakfire, "Verifying filelist (%zu file(s))...\n", length);
+ CTX_DEBUG(list->ctx, "Verifying filelist (%zu file(s))...\n", length);
// Setup progress
r = pakfire_progress_create(&progress, list->ctx,