// Setup progress callback
pakfire_ctx_set_progress_callback(ctx, cli_setup_progressbar, NULL);
+ // Set the default cache path
+ r = pakfire_ctx_set_cache_path(ctx, "~/.cache/pakfire");
+ if (r)
+ goto ERROR;
+
struct cli_config config = {
.ctx = ctx,
.distro = cli_get_default_distro(ctx),
#include <ctype.h>
#include <errno.h>
+#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
+#include <wordexp.h>
#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/logging.h>
#include <pakfire/os.h>
#include <pakfire/private.h>
+#include <pakfire/string.h>
struct pakfire_ctx {
// Reference counter
void* data;
} log;
+ // Paths
+ struct pakfire_ctx_paths {
+ char cache[PATH_MAX];
+ } paths;
+
// Confirm
struct pakfire_ctx_confirm {
pakfire_confirm_callback callback;
if (r)
goto ERROR;
+ // Setup the default cache path
+ r = pakfire_ctx_set_cache_path(c, PAKFIRE_CACHE_DIR);
+ if (r)
+ goto ERROR;
+
// Load the distribution information
r = pakfire_distro(&c->distro, NULL);
if (r)
va_end(args);
}
+// Paths
+
+PAKFIRE_EXPORT const char* pakfire_ctx_get_cache_path(struct pakfire_ctx* ctx) {
+ return ctx->paths.cache;
+}
+
+PAKFIRE_EXPORT int pakfire_ctx_set_cache_path(struct pakfire_ctx* ctx, const char* path) {
+ wordexp_t result = {};
+ int r;
+
+ // Expand the path
+ r = wordexp(path, &result, 0);
+ if (r) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // There should only be one result
+ if (result.we_wordc != 1) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Store the result
+ r = pakfire_string_set(ctx->paths.cache, result.we_wordv[0]);
+ if (r)
+ goto ERROR;
+
+ CTX_DEBUG(ctx, "Set cache path to %s\n", ctx->paths.cache);
+
+ERROR:
+ wordfree(&result);
+
+ return r;
+}
+
// Confirm
PAKFIRE_EXPORT void pakfire_ctx_set_confirm_callback(struct pakfire_ctx* ctx,
void pakfire_ctx_set_log_callback(struct pakfire_ctx* ctx,
pakfire_log_callback callback, void* data);
+// Paths
+
+const char* pakfire_ctx_get_cache_path(struct pakfire_ctx* ctx);
+int pakfire_ctx_set_cache_path(struct pakfire_ctx* ctx, const char* path);
+
// Confirm
typedef int (*pakfire_confirm_callback)(struct pakfire_ctx* ctx, struct pakfire* pakfire,
pakfire_ctx_set_pick_solution_callback;
pakfire_ctx_has_flag;
pakfire_ctx_set_flag;
+ pakfire_ctx_get_cache_path;
+ pakfire_ctx_set_cache_path;
# pakfire
pakfire_check;
}
static int pakfire_set_cache_path(struct pakfire* pakfire) {
- char basepath[PATH_MAX];
- int r;
-
+ const char* cache_path = pakfire_ctx_get_cache_path(pakfire->ctx);
const char* arch = pakfire_get_effective_arch(pakfire);
- // Fetch the path from the configuration file
- const char* path = pakfire_config_get(pakfire->config, "general", "cache_path", NULL);
- if (!path) {
- // Append a suffix to the home directory
- r = pakfire_string_format(basepath, "%s/.pakfire/cache", pakfire->user.home);
- if (r)
- return 1;
-
- // Use the basepath as path
- path = basepath;
- }
-
// Format the final path
return pakfire_string_format(pakfire->cache_path, "%s/%s/%s/%s",
- path, pakfire->distro.id, pakfire->distro.version_id, arch);
+ cache_path, pakfire->distro.id, pakfire->distro.version_id, arch);
}
static int pakfire_setup_user(struct pakfire* pakfire) {