From: Michael Tremer Date: Mon, 19 Apr 2021 15:12:00 +0000 (+0000) Subject: pakfire_make_cache_path: Implicitely handle size argument X-Git-Tag: 0.9.28~1285^2~326 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a5ef40501da23d3dc5892b2307178f0f89f124fc;p=pakfire.git pakfire_make_cache_path: Implicitely handle size argument Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index a7c162fe6..4bb66797d 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -163,8 +163,7 @@ static int pakfire_dist_add_source(Pakfire pakfire, struct pakfire_packager* pac char cache_path[PATH_MAX]; const char* name = pakfire_package_get_name(pkg); - pakfire_make_cache_path(pakfire, cache_path, sizeof(cache_path) - 1, - "sources/%s/%s", name, filename); + pakfire_make_cache_path(pakfire, cache_path, "sources/%s/%s", name, filename); // Download the file if it does not exist in the cache if (access(cache_path, R_OK) != 0) { diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index a81faf31e..a8063b13e 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -84,9 +84,11 @@ int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, const char* pa #include -int pakfire_make_cache_path(Pakfire pakfire, char* path, size_t length, - const char* format, ...) - __attribute__((format(printf, 4, 5))); +#define pakfire_make_cache_path(pakfire, path, format, ...) \ + __pakfire_make_cache_path(pakfire, path, sizeof(path) - 1, format, __VA_ARGS__) + +int __pakfire_make_cache_path(Pakfire pakfire, char* path, size_t length, + const char* format, ...) __attribute__((format(printf, 4, 5))); void pakfire_pool_has_changed(Pakfire pakfire); void pakfire_pool_apply_changes(Pakfire pakfire); diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 1825de4d1..2fd341071 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -913,7 +913,7 @@ PAKFIRE_EXPORT char* pakfire_package_get_cache_path(PakfirePackage pkg) { if (strlen(checksum) < 3) return NULL; - pakfire_make_cache_path(pkg->pakfire, path, sizeof(path) - 1, + pakfire_make_cache_path(pkg->pakfire, path, "%c%c/%s/%s", checksum[0], checksum[1], checksum + 2, filename); return strdup(path); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 6e74f67f3..0635c49f9 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -1148,7 +1148,7 @@ PAKFIRE_EXPORT PakfirePackageList pakfire_search(Pakfire pakfire, const char* wh // Cache -int pakfire_make_cache_path(Pakfire pakfire, char* path, size_t length, +int __pakfire_make_cache_path(Pakfire pakfire, char* path, size_t length, const char* format, ...) { va_list args; @@ -1174,7 +1174,7 @@ int pakfire_make_cache_path(Pakfire pakfire, char* path, size_t length, PAKFIRE_EXPORT int pakfire_cache_destroy(Pakfire pakfire, const char* path) { char cache_path[PATH_MAX]; - pakfire_make_cache_path(pakfire, cache_path, sizeof(cache_path) - 1, "%s", path); + pakfire_make_cache_path(pakfire, cache_path, "%s", path); // Completely delete the tree of files return pakfire_rmtree(cache_path, 0); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 9df53bc8a..4e4837514 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -259,7 +259,7 @@ static int pakfire_repo_read_metadata(PakfireRepo repo, const char* path, int re // Try loading the database if (*database_filename) { - pakfire_make_cache_path(repo->pakfire, database_cache_path, sizeof(database_cache_path) -1, + pakfire_make_cache_path(repo->pakfire, database_cache_path, "repodata/%s/%s", pakfire_repo_get_name(repo), database_filename); // Download the database if necessary @@ -427,13 +427,13 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name return repo; // Make path to mirrorlist - r = pakfire_make_cache_path(pakfire, repo->appdata->mirrorlist, sizeof(repo->appdata->mirrorlist) - 1, + r = pakfire_make_cache_path(pakfire, repo->appdata->mirrorlist, "repodata/%s/mirrorlist", pakfire_repo_get_name(repo)); if (r < 0) goto ERROR; // Make path for metadata - r = pakfire_make_cache_path(pakfire, repo->appdata->metadata, sizeof(repo->appdata->metadata) - 1, + r = pakfire_make_cache_path(pakfire, repo->appdata->metadata, "repodata/%s/repomd.json", pakfire_repo_get_name(repo)); if (r < 0) goto ERROR; @@ -843,7 +843,7 @@ PAKFIRE_EXPORT PakfirePackage pakfire_repo_add_archive(PakfireRepo repo, Pakfire PAKFIRE_EXPORT int pakfire_repo_clean(PakfireRepo repo) { char cache_path[PATH_MAX]; - int r = pakfire_make_cache_path(repo->pakfire, cache_path, sizeof(cache_path) - 1, + int r = pakfire_make_cache_path(repo->pakfire, cache_path, "%s", pakfire_repo_get_name(repo)); if (r < 0) return r;