]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
repo: Compress the SOLV database using Zstandard
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Mar 2023 11:48:18 +0000 (11:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Mar 2023 11:17:28 +0000 (11:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index 92924e811f37082958b8cce5a332dc7900024aac..ee4a84c5425c2c44adb83811fb9c4164e28f9989 100644 (file)
@@ -990,9 +990,12 @@ ERROR:
 }
 
 PAKFIRE_EXPORT int pakfire_repo_read_solv(struct pakfire_repo* repo, FILE *f, int flags) {
+       // Automatically detect compression
        f = pakfire_xfopen(f, "r");
-       if (!f)
+       if (!f) {
+               errno = ENOTSUP;
                return 1;
+       }
 
        int ret = repo_add_solv(repo->repo, f, flags);
        switch (ret) {
@@ -1339,6 +1342,13 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa
                return 1;
        }
 
+       // Initialize the output being compressed
+       f = pakfire_zstdfopen(f, "w");
+       if (!f) {
+               ERROR(repo->pakfire, "Could not initialize compression: %m\n");
+               return 1;
+       }
+
        // Write the SOLV database to the temporary file
        r = pakfire_repo_write_solv(repo, f, 0);
        if (r) {
@@ -1351,7 +1361,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa
        f = NULL;
 
        // Create a filename for the database file
-       r = __pakfire_strftime_now(filename, length, "%Y-%m-%d-%H%M.%s.solv");
+       r = __pakfire_strftime_now(filename, length, "%Y-%m-%d-%H%M.%s.solv.zst");
        if (r) {
                ERROR(repo->pakfire, "Could not format database filename: %m\n");
                goto ERROR;