return r;
}
-int pakfire_file_read(struct pakfire_file* file, struct archive* reader, const char* path) {
- int r;
-
- // Check inputs
- if (!reader || !path)
- return -EINVAL;
-
- // Set abspath
- archive_entry_copy_sourcepath(file->entry, path);
-
- // Read everything
- r = archive_read_disk_entry_from_file(reader, file->entry, -1, NULL);
- if (r) {
- CTX_ERROR(file->ctx, "Could not read %s: %s\n", path, archive_error_string(reader));
- return 1;
- }
-
- return 0;
-}
-
int pakfire_file_create_from_archive_entry(struct pakfire_file** file, struct pakfire* pakfire,
struct archive_entry* entry) {
struct pakfire_file* f = NULL;
#include <time.h>
#include <unistd.h>
+// libarchive
#include <archive.h>
#include <archive_entry.h>
int pakfire_packager_add(struct pakfire_packager* packager,
const char* sourcepath, const char* path) {
+ struct archive_entry* entry = NULL;
struct pakfire_file* file = NULL;
int r;
- if (!path)
- path = sourcepath;
+ // Check inputs
+ if (!sourcepath || !path)
+ return -EINVAL;
- // Create a new file object
- r = pakfire_file_create(&file, packager->pakfire, path);
- if (r < 0)
- goto ERROR;
+ // Create a new archive entry
+ entry = archive_entry_new();
+ if (!entry)
+ return -errno;
+
+ // Set the path
+ archive_entry_copy_pathname(entry, path);
+
+ // Set the absolute path
+ archive_entry_copy_sourcepath(entry, sourcepath);
- // Read the meta information
- r = pakfire_file_read(file, packager->reader, sourcepath);
- if (r < 0)
+ // Read everything
+ r = archive_read_disk_entry_from_file(packager->reader, entry, -1, NULL);
+ if (r) {
+ ERROR(packager->pakfire, "Could not read %s: %s\n",
+ sourcepath, archive_error_string(packager->reader));
+ r = -errno;
goto ERROR;
+ }
- // Assign a new path for inside the archive
- r = pakfire_file_set_path(file, path);
- if (r < 0)
+ // Create a new file object from the archive entry
+ r = pakfire_file_create_from_archive_entry(&file, packager->pakfire, entry);
+ if (r < 0) {
+ ERROR(packager->pakfire, "Could not create file object: %s\n", strerror(-r));
goto ERROR;
+ }
// Call the main function
r = pakfire_packager_add_file(packager, file);
ERROR:
if (file)
pakfire_file_unref(file);
+ if (entry)
+ archive_entry_free(entry);
return r;
}
// Add a file to the package
const char* path = TEST_SRC_PATH "data/beep-1.3-2.ip3.x86_64.pfm";
- ASSERT_SUCCESS(pakfire_packager_add(packager, path, NULL));
+ ASSERT_SUCCESS(pakfire_packager_add(packager, path, "beep-1.3-2.ip3.x86_64.pfm"));
// Write archive
FILE* f = test_mktemp(NULL);