]> git.ipfire.org Git - pakfire.git/commitdiff
file: Make importer from archive entry private
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Aug 2022 09:28:54 +0000 (09:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Aug 2022 09:28:54 +0000 (09:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c
src/libpakfire/include/pakfire/file.h

index 43399126801e8f82d4fbb78134f686095982f7ac..eb9c0d36ff8ade16fad22829b7e9b789064e98e7 100644 (file)
@@ -106,6 +106,80 @@ static int __pakfire_file_has_digest(const unsigned char* digest, const size_t l
        return 0;
 }
 
+static int pakfire_file_from_archive_entry(struct pakfire_file* file, struct archive_entry* entry) {
+       const char* attr = NULL;
+       const void* value = NULL;
+       size_t size = 0;
+       int r = 0;
+
+       // Set abspath
+       r = pakfire_file_set_abspath(file, archive_entry_sourcepath(entry));
+       if (r) {
+               ERROR(file->pakfire, "Could not set abspath: %m\n");
+               goto ERROR;
+       }
+
+       // Set path
+       const char* path = archive_entry_pathname(entry);
+       if (path) {
+               // Strip any leading dots from paths
+               if (pakfire_string_startswith(path, "./"))
+                       path++;
+
+               r = pakfire_file_set_path(file, path);
+               if (r) {
+                       ERROR(file->pakfire, "Could not set path: %m\n");
+                       goto ERROR;
+               }
+       }
+
+       // Set links
+       pakfire_file_set_hardlink(file, archive_entry_hardlink(entry));
+       pakfire_file_set_symlink(file, archive_entry_symlink(entry));
+
+       // Set size
+       pakfire_file_set_size(file, archive_entry_size(entry));
+
+       // Set mode
+       pakfire_file_set_mode(file, archive_entry_mode(entry));
+
+       // Set dev type
+       if (archive_entry_dev_is_set(entry))
+               pakfire_file_set_dev(file, archive_entry_dev(entry));
+
+       // Set user
+       pakfire_file_set_user(file, archive_entry_uname(entry));
+
+       // Set group
+       pakfire_file_set_group(file, archive_entry_gname(entry));
+
+       // Set times
+       pakfire_file_set_ctime(file, archive_entry_ctime(entry));
+       pakfire_file_set_mtime(file, archive_entry_mtime(entry));
+
+       // Read any extended attributes
+       while (archive_entry_xattr_next(entry, &attr, &value, &size) == ARCHIVE_OK) {
+               // Digest: SHA-512
+               if (strcmp(attr, "PAKFIRE.digests.sha512") == 0) {
+                       r = pakfire_file_set_digest(file, PAKFIRE_DIGEST_SHA512, value, size);
+                       if (r)
+                               goto ERROR;
+
+               // Digest: SHA-256
+               } else if (strcmp(attr, "PAKFIRE.digests.sha256") == 0) {
+                       r = pakfire_file_set_digest(file, PAKFIRE_DIGEST_SHA256, value, size);
+                       if (r)
+                               goto ERROR;
+
+               } else {
+                       DEBUG(file->pakfire, "Received an unknown extended attribute: %s\n", attr);
+               }
+       }
+
+ERROR:
+       return r;
+}
+
 PAKFIRE_EXPORT int pakfire_file_create(struct pakfire_file** file, struct pakfire* pakfire) {
        struct pakfire_file* f = calloc(1, sizeof(*f));
        if (!f)
@@ -170,7 +244,7 @@ int pakfire_file_create_from_archive_entry(struct pakfire_file** file, struct pa
                return r;
 
        // Copy archive entry
-       r = pakfire_file_copy_archive_entry(*file, entry);
+       r = pakfire_file_from_archive_entry(*file, entry);
        if (r)
                goto ERROR;
 
@@ -183,72 +257,6 @@ ERROR:
        return r;
 }
 
-int pakfire_file_copy_archive_entry(struct pakfire_file* file, struct archive_entry* entry) {
-       const char* attr = NULL;
-       const void* value = NULL;
-       size_t size = 0;
-       int r = 0;
-
-       // Set abspath
-       pakfire_file_set_abspath(file, archive_entry_sourcepath(entry));
-
-       // Set path
-       const char* path = archive_entry_pathname(entry);
-       if (path) {
-               // Strip any leading dots from paths
-               if (pakfire_string_startswith(path, "./"))
-                       path++;
-
-               pakfire_file_set_path(file, path);
-       }
-
-       // Set links
-       pakfire_file_set_hardlink(file, archive_entry_hardlink(entry));
-       pakfire_file_set_symlink(file, archive_entry_symlink(entry));
-
-       // Set size
-       pakfire_file_set_size(file, archive_entry_size(entry));
-
-       // Set mode
-       pakfire_file_set_mode(file, archive_entry_mode(entry));
-
-       // Set dev type
-       if (archive_entry_dev_is_set(entry))
-               pakfire_file_set_dev(file, archive_entry_dev(entry));
-
-       // Set user
-       pakfire_file_set_user(file, archive_entry_uname(entry));
-
-       // Set group
-       pakfire_file_set_group(file, archive_entry_gname(entry));
-
-       // Set times
-       pakfire_file_set_ctime(file, archive_entry_ctime(entry));
-       pakfire_file_set_mtime(file, archive_entry_mtime(entry));
-
-       // Read any extended attributes
-       while (archive_entry_xattr_next(entry, &attr, &value, &size) == ARCHIVE_OK) {
-               // Digest: SHA-512
-               if (strcmp(attr, "PAKFIRE.digests.sha512") == 0) {
-                       r = pakfire_file_set_digest(file, PAKFIRE_DIGEST_SHA512, value, size);
-                       if (r)
-                               goto ERROR;
-
-               // Digest: SHA-256
-               } else if (strcmp(attr, "PAKFIRE.digests.sha256") == 0) {
-                       r = pakfire_file_set_digest(file, PAKFIRE_DIGEST_SHA256, value, size);
-                       if (r)
-                               goto ERROR;
-
-               } else {
-                       DEBUG(file->pakfire, "Received an unknown extended attribute: %s\n", attr);
-               }
-       }
-
-ERROR:
-       return r;
-}
-
 struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file) {
        struct archive_entry* entry = archive_entry_new();
        if (!entry) {
index 5411a7a7df2602c7255da91638f1a329143ad1dc..fa91e8c9aa31b3c7d170ed619adfd48616f9b945 100644 (file)
@@ -86,7 +86,6 @@ int pakfire_file_create_from_path(struct pakfire_file** file,
        struct pakfire* pakfire, const char* path);
 int pakfire_file_create_from_archive_entry(struct pakfire_file** file, struct pakfire* pakfire,
        struct archive_entry* entry);
-int pakfire_file_copy_archive_entry(struct pakfire_file* file, struct archive_entry* entry);
 struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file);
 
 const char* pakfire_file_get_abspath(struct pakfire_file* file);