}
// Compose path
- r = pakfire_make_cache_path(build->pakfire, path, "%s", "ccache");
- if (r < 0) {
+ r = pakfire_cache_path(build->pakfire, path, "%s", "ccache");
+ if (r) {
ERROR(build->pakfire, "Could not compose ccache path: %m\n");
return 1;
}
}
// Compose path for snapshot
- r = pakfire_make_cache_path(build->pakfire, path, "%s", "snapshot.tar.zst");
- if (r < 0) {
+ r = pakfire_cache_path(build->pakfire, path, "%s", "snapshot.tar.zst");
+ if (r) {
ERROR(build->pakfire, "Could not compose snapshot path: %m\n");
return 1;
}
char cache_path[PATH_MAX];
const char* name = pakfire_package_get_name(pkg);
- pakfire_make_cache_path(pakfire, cache_path, "sources/%s/%s", name, filename);
+
+ // Compose path
+ r = pakfire_cache_path(pakfire, cache_path, "sources/%s/%s", name, filename);
+ if (r)
+ return r;
// Download the file if it does not exist in the cache
if (access(cache_path, R_OK) != 0) {
const char* pakfire_relpath(struct pakfire* pakfire, const char* path);
-#define pakfire_make_cache_path(pakfire, path, format, ...) \
- __pakfire_make_cache_path(pakfire, path, sizeof(path), format, __VA_ARGS__)
-
-int __pakfire_make_cache_path(struct pakfire* pakfire, char* path, size_t length,
+#define pakfire_cache_path(pakfire, path, format, ...) \
+ __pakfire_cache_path(pakfire, path, sizeof(path), format, __VA_ARGS__)
+int __pakfire_cache_path(struct pakfire* pakfire, char* path, size_t length,
const char* format, ...) __attribute__((format(printf, 4, 5)));
void pakfire_pool_has_changed(struct pakfire* pakfire);
const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest);
if (hexdigest && strlen(hexdigest) >= 3)
- return pakfire_make_cache_path(pkg->pakfire, pkg->path,
+ return pakfire_cache_path(pkg->pakfire, pkg->path,
"%c%c/%s/%s", hexdigest[0], hexdigest[1], hexdigest + 2, filename);
- return pakfire_make_cache_path(pkg->pakfire, pkg->path, "%s", filename);
+ return pakfire_cache_path(pkg->pakfire, pkg->path, "%s", filename);
}
PAKFIRE_EXPORT const char* pakfire_package_get_path(struct pakfire_package* pkg) {
return pakfire_path_relpath(pakfire->path, path);
}
+int __pakfire_cache_path(struct pakfire* pakfire, char* path, size_t length,
+ const char* format, ...) {
+ char buffer[PATH_MAX];
+ va_list args;
+ int r;
+
+ // Format input into buffer
+ va_start(args, format);
+ r = __pakfire_string_vformat(buffer, sizeof(buffer), format, args);
+ va_end(args);
+
+ // Break on any errors
+ if (r)
+ return r;
+
+ // Join paths together
+ return __pakfire_path_join(path, length, pakfire->cache_path, buffer);
+}
+
gpgme_ctx_t pakfire_get_gpgctx(struct pakfire* pakfire) {
return pakfire->gpgctx;
}
return r;
}
-// Cache
-
-int __pakfire_make_cache_path(struct pakfire* pakfire, char* path, size_t length,
- const char* format, ...) {
- va_list args;
-
- // Write cache path
- ssize_t l = snprintf(path, length - 1, "%s/", pakfire->cache_path);
- if (l < 0)
- return l;
-
- // We have run out of space
- if ((size_t)l >= length)
- return -1;
-
- // Append everything after the format string
- path += l;
-
- va_start(args, format);
- vsnprintf(path, length - l - 1, format, args);
- va_end(args);
-
- return 0;
-}
-
// Logging
PAKFIRE_EXPORT int pakfire_log_get_priority(struct pakfire* pakfire) {
// Try loading the database
if (*database_filename) {
- pakfire_make_cache_path(repo->pakfire, database_cache_path,
+ r = pakfire_cache_path(repo->pakfire, database_cache_path,
"repodata/%s/%s", pakfire_repo_get_name(repo), database_filename);
+ if (r)
+ goto ERROR;
// Download the database if necessary
if (refresh) {
goto SUCCESS;
// Make path to mirrorlist
- r = pakfire_make_cache_path(pakfire, rep->appdata->mirrorlist,
+ r = pakfire_cache_path(pakfire, rep->appdata->mirrorlist,
"repodata/%s/mirrorlist", pakfire_repo_get_name(rep));
- if (r < 0)
+ if (r)
goto ERROR;
// Make path for metadata
- r = pakfire_make_cache_path(pakfire, rep->appdata->metadata,
+ r = pakfire_cache_path(pakfire, rep->appdata->metadata,
"repodata/%s/repomd.json", pakfire_repo_get_name(rep));
- if (r < 0)
+ if (r)
goto ERROR;
// Try loading metadata
}
// Destroy all files in the cache directory
- r = pakfire_make_cache_path(repo->pakfire, cache_path,
+ r = pakfire_cache_path(repo->pakfire, cache_path,
"repodata/%s", pakfire_repo_get_name(repo));
- if (r < 0)
+ if (r)
return r;
return pakfire_rmtree(cache_path, 0);