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)
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;
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) {