From: Michael Tremer Date: Fri, 12 Mar 2021 18:59:21 +0000 (+0000) Subject: cache: Make formatting cache filenames easier X-Git-Tag: 0.9.28~1285^2~548 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c421d973139958efd353e012ba02265700aabaf7;p=pakfire.git cache: Make formatting cache filenames easier Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index feb841563..5ab5d6179 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -60,7 +60,6 @@ PakfirePackageList pakfire_search(Pakfire pakfire, const char* what, int flags); const char* pakfire_get_cache_path(Pakfire pakfire); void pakfire_set_cache_path(Pakfire pakfire, const char* path); -char* pakfire_make_cache_path(Pakfire pakfire, const char* path); int pakfire_cache_destroy(Pakfire pakfire, const char* path); int pakfire_cache_access(Pakfire pakfire, const char* path, int mode); @@ -88,6 +87,8 @@ int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, const char* pa #include +char* pakfire_make_cache_path(Pakfire pakfire, const char* format, ...); + void pakfire_pool_has_changed(Pakfire pakfire); void pakfire_pool_apply_changes(Pakfire pakfire); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index b1ace36ec..805beab20 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -662,7 +662,15 @@ PAKFIRE_EXPORT void pakfire_set_cache_path(Pakfire pakfire, const char* path) { snprintf(pakfire->cache_path, sizeof(pakfire->cache_path) - 1, "%s", path); } -PAKFIRE_EXPORT char* pakfire_make_cache_path(Pakfire pakfire, const char* path) { +PAKFIRE_EXPORT char* pakfire_make_cache_path(Pakfire pakfire, const char* format, ...) { + char path[PATH_MAX]; + va_list args; + + va_start(args, format); + vsnprintf(path, sizeof(PATH_MAX) - 1, format, args); + va_end(args); + + // Prepend cache path return pakfire_path_join(pakfire->cache_path, path); } diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 90e69883e..ce2a5c598 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -61,7 +61,7 @@ struct pakfire_repo_appdata { // Mirrorlist char* mirrorlist_url; - char mirrorlist[PATH_MAX]; + char* mirrorlist; }; struct _PakfireRepo { @@ -116,6 +116,9 @@ static void free_repo_appdata(struct pakfire_repo_appdata* appdata) { if (appdata->mirrorlist_url) free(appdata->mirrorlist_url); + if (appdata->mirrorlist) + free(appdata->mirrorlist); + free(appdata); } @@ -153,9 +156,8 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL|REPO_NO_INTERNALIZE|REPO_NO_LOCATION); // Make path to mirrorlist - snprintf(repo->appdata->mirrorlist, sizeof(repo->appdata->mirrorlist) - 1, - "%s/repodata/%s/mirrorlist", pakfire_get_cache_path(repo->pakfire), - pakfire_repo_get_name(repo)); + repo->appdata->mirrorlist = pakfire_make_cache_path( + repo->pakfire, "repodata/%s/mirrorlist", pakfire_repo_get_name(repo)); } return repo;