]> git.ipfire.org Git - pakfire.git/commitdiff
cache: Make formatting cache filenames easier
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Mar 2021 18:59:21 +0000 (18:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Mar 2021 18:59:21 +0000 (18:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
src/libpakfire/repo.c

index feb8415632ca4b9ada625d2bf32ecefe4e18d751..5ab5d6179087f12302e0c33d93c618500732cca9 100644 (file)
@@ -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 <solv/pool.h>
 
+char* pakfire_make_cache_path(Pakfire pakfire, const char* format, ...);
+
 void pakfire_pool_has_changed(Pakfire pakfire);
 void pakfire_pool_apply_changes(Pakfire pakfire);
 
index b1ace36ecea5b0870c919cb6af34f89cf5cd6c9f..805beab20ef51dade667b89b0fe80f2e3d45a001 100644 (file)
@@ -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);
 }
 
index 90e69883e78187d66c69732c12b37323a6d9857d..ce2a5c598eb88b807c0a002c70f3bed847e093a1 100644 (file)
@@ -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;