]> git.ipfire.org Git - pakfire.git/commitdiff
compress: Move function to read payload from util
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 12:34:43 +0000 (12:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 12:34:43 +0000 (12:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/compress.c
src/libpakfire/include/pakfire/util.h
src/libpakfire/util.c

index 316a2139de1a8148fb0659315c1bc261eedc6119..c9ebce24859bdcaeb8f897970b3f21d76d91c5b6 100644 (file)
@@ -890,6 +890,38 @@ struct pakfire_compress {
        int digests;
 };
 
+static int pakfire_copy_data_from_file(struct pakfire* pakfire,
+               struct archive* archive, FILE* f) {
+       char buffer[BUFFER_SIZE];
+
+       ssize_t bytes_read = 0;
+       ssize_t bytes_written = 0;
+
+       // Read file from the very beginning - also allows calling this multiple times
+       rewind(f);
+
+       // Loop through the entire length of the file
+       while (!feof(f)) {
+               // Read a block from file
+               bytes_read = fread(buffer, 1, sizeof(buffer), f);
+
+               // Check if any error occured
+               if (ferror(f)) {
+                       ERROR(pakfire, "Read error: %m\n");
+                       return -errno;
+               }
+
+               // Write the block to the archive
+               bytes_written = archive_write_data(archive, buffer, bytes_read);
+               if (bytes_written < bytes_read) {
+                       ERROR(pakfire, "Write error: %s\n", archive_error_string(archive));
+                       return -errno;
+               }
+       }
+
+       return 0;
+}
+
 static int __pakfire_compress_entry(struct pakfire* pakfire, struct pakfire_file* file,
                struct pakfire_compress* data, struct archive_entry* entry) {
        FILE* f = NULL;
@@ -921,7 +953,7 @@ static int __pakfire_compress_entry(struct pakfire* pakfire, struct pakfire_file
                }
 
                // Copy the payload into the archive
-               r = pakfire_archive_copy_data_from_file(pakfire, data->archive, f);
+               r = pakfire_copy_data_from_file(pakfire, data->archive, f);
                if (r)
                        goto ERROR;
        }
index 14b54dfc160109f5f0fff854e7c1e1d4b9f10131..bcc87ad3623242e3de0f6ca1d38d2ec03e1ebef0 100644 (file)
@@ -26,8 +26,6 @@
 #include <pwd.h>
 #include <stdio.h>
 
-#include <archive.h>
-
 #define PCRE2_CODE_UNIT_WIDTH 8
 #include <pcre2.h>
 
@@ -86,11 +84,6 @@ char* pakfire_generate_uuid(void);
 
 int pakfire_tty_is_noninteractive(void);
 
-// Archive Stuff
-
-int pakfire_archive_copy_data_from_file(struct pakfire* pakfire,
-       struct archive* archive, FILE* f);
-
 // JSON Stuff
 
 struct json_object* pakfire_json_parse(struct pakfire_ctx* ctx,
index 9aa1993f4a13ee27fdcb97b630f0830605c4717f..b2b07bd3fb0ca943ce225b8f526ba2546547704e 100644 (file)
@@ -33,8 +33,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <archive.h>
-#include <archive_entry.h>
 #include <json.h>
 #include <uuid/uuid.h>
 
@@ -643,40 +641,6 @@ int __pakfire_which(struct pakfire* pakfire, char* path, const size_t length,
        return 0;
 }
 
-// Archive Stuff
-
-int pakfire_archive_copy_data_from_file(struct pakfire* pakfire,
-               struct archive* archive, FILE* f) {
-       char buffer[BUFFER_SIZE];
-
-       size_t bytes_read = 0;
-       ssize_t bytes_written = 0;
-
-       // Read file from the very beginning - also allows calling this multiple times
-       rewind(f);
-
-       // Loop through the entire length of the file
-       while (!feof(f)) {
-               // Read a block from file
-               bytes_read = fread(buffer, 1, sizeof(buffer), f);
-
-               // Check if any error occured
-               if (ferror(f)) {
-                       ERROR(pakfire, "Read error: %m\n");
-                       return 1;
-               }
-
-               // Write the block to the archive
-               bytes_written = archive_write_data(archive, buffer, bytes_read);
-               if (bytes_written < 0) {
-                       ERROR(pakfire, "Write error: %s\n", archive_error_string(archive));
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
 // JSON Stuff
 
 struct json_object* pakfire_json_parse(struct pakfire_ctx* ctx,