#include <syslog.h>
#include <wordexp.h>
+#include <magic.h>
+
#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/logging.h>
pakfire_pick_solution_callback callback;
void* data;
} pick_solution;
+
+ // Magic Context
+ magic_t magic;
};
static int parse_log_level(const char* level) {
}
static void pakfire_ctx_free(struct pakfire_ctx* ctx) {
+ // Release Magic Context
+ if (ctx->magic)
+ magic_close(ctx->magic);
if (ctx->config)
pakfire_config_unref(ctx->config);
free(ctx);
return ctx->pick_solution.callback(ctx, pakfire, ctx->pick_solution.data, transaction);
}
+
+// Magic
+
+magic_t pakfire_ctx_magic(struct pakfire_ctx* ctx) {
+ int r;
+
+ // Initialize the context if not already done
+ if (!ctx->magic) {
+ // Allocate a new context
+ ctx->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR | MAGIC_NO_CHECK_TOKENS);
+ if (!ctx->magic) {
+ CTX_ERROR(ctx, "Could not allocate magic context: %m\n");
+ return NULL;
+ }
+
+ // Load the database
+ r = magic_load(ctx->magic, NULL);
+ if (r) {
+ CTX_ERROR(ctx, "Could not open the magic database: %s\n", magic_error(ctx->magic));
+ goto ERROR;
+ }
+ }
+
+ return ctx->magic;
+
+ERROR:
+ if (ctx->magic)
+ magic_close(ctx->magic);
+
+ // Reset the pointer
+ ctx->magic = NULL;
+
+ return NULL;
+}
return 0;
// Fetch the magic cookie
- magic_t magic = pakfire_get_magic(file->pakfire);
+ magic_t magic = pakfire_ctx_magic(file->ctx);
if (!magic)
return 1;
int pakfire_ctx_pick_solution(struct pakfire_ctx* ctx, struct pakfire* pakfire,
struct pakfire_transaction* transaction);
+// Magic
+
+#include <magic.h>
+
+magic_t pakfire_ctx_magic(struct pakfire_ctx* ctx);
+
#endif /* PAKFIRE_PRIVATE */
#endif /* PAKFIRE_CTX_H */
#include <sys/types.h>
-#include <magic.h>
#include <solv/pool.h>
#include <pakfire/config.h>
int pakfire_pick_solution(struct pakfire* pakfire, struct pakfire_transaction* transaction);
int pakfire_setup_progress(struct pakfire* pakfire, struct pakfire_progress* progress);
-magic_t pakfire_get_magic(struct pakfire* pakfire);
-
const char* pakfire_get_distro_name(struct pakfire* pakfire);
const char* pakfire_get_distro_id(struct pakfire* pakfire);
const char* pakfire_get_distro_vendor(struct pakfire* pakfire);
#include <archive.h>
#include <archive_entry.h>
-#include <magic.h>
#include <solv/evr.h>
#include <solv/pool.h>
#include <solv/poolarch.h>
// Distro
struct pakfire_distro distro;
- // Magic Context
- magic_t magic;
-
// States
unsigned int destroy_on_free:1;
unsigned int pool_ready:1;
pakfire_repo_unref(repo);
}
- // Release Magic Context
- if (pakfire->magic)
- magic_close(pakfire->magic);
-
// Release lock (if not already done so)
pakfire_release_lock(pakfire);
return __pakfire_path_append(path, length, pakfire->cache_path, buffer);
}
-magic_t pakfire_get_magic(struct pakfire* pakfire) {
- int r;
-
- // Initialize the context if not already done
- if (!pakfire->magic) {
- // Allocate a new context
- pakfire->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR | MAGIC_NO_CHECK_TOKENS);
- if (!pakfire->magic) {
- CTX_ERROR(pakfire->ctx, "Could not allocate magic context: %m\n");
- return NULL;
- }
-
- // Load the database
- r = magic_load(pakfire->magic, NULL);
- if (r) {
- CTX_ERROR(pakfire->ctx, "Could not open the magic database: %s\n",
- magic_error(pakfire->magic));
- goto ERROR;
- }
- }
-
- return pakfire->magic;
-
-ERROR:
- if (pakfire->magic)
- magic_close(pakfire->magic);
-
- // Reset the pointer
- pakfire->magic = NULL;
-
- return NULL;
-}
-
int pakfire_repo_walk(struct pakfire* pakfire,
pakfire_repo_walk_callback callback, void* p) {
struct pakfire_repo* repo = NULL;