return r;
}
+static int pakfire_set_cache_path(struct pakfire* pakfire) {
+ char basepath[PATH_MAX];
+ int r;
+
+ // Fetch the path from the configuration file
+ const char* path = pakfire_config_get(pakfire->config, "general", "cache_path", NULL);
+ if (!path) {
+ const char* home = pakfire_get_home(pakfire, pakfire->uid);
+ if (!home)
+ return 1;
+
+ // Append a suffix to the home directory
+ r = pakfire_string_format(basepath, "%s/.pakfire/cache", 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, pakfire->arch);
+}
+
PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
const char* arch, const char* conf, int flags,
int loglevel, pakfire_log_callback log_callback, void* log_data) {
}
// Set cache path
- if (p->uid) {
- const char* home = pakfire_get_home(p, p->uid);
- if (!home) {
- ERROR(p, "Could not find home directory\n");
- errno = ENOENT;
- goto ERROR;
- }
-
- pakfire_string_format(p->cache_path, "%s/.pakfire/cache/%s/%s/%s",
- home, p->distro.id, p->distro.version_id, p->arch);
- } else {
- pakfire_string_format(p->cache_path, "%s/%s/%s/%s",
- PAKFIRE_CACHE_DIR, p->distro.id, p->distro.version_id, p->arch);
+ r = pakfire_set_cache_path(p);
+ if (r) {
+ ERROR(p, "Could not set cache path: %m\n");
+ goto ERROR;
}
// Set keystore path