return 0;
}
+int pakfire_file_create_from_path(struct pakfire_file** file,
+ struct pakfire* pakfire, const char* path) {
+ struct archive* reader = NULL;
+ struct archive_entry* entry = NULL;
+ int r = 1;
+
+ // Allocate a reader
+ reader = pakfire_make_archive_disk_reader(pakfire, 0);
+ if (!reader)
+ goto ERROR;
+
+ // Allocate a new archive entry
+ entry = archive_entry_new();
+ if (!entry)
+ goto ERROR;
+
+ // Set source path
+ archive_entry_copy_sourcepath(entry, path);
+
+ // Read all file attributes from disk
+ r = archive_read_disk_entry_from_file(reader, entry, -1, NULL);
+ if (r) {
+ ERROR(pakfire, "Could not read from %s: %m\n", path);
+ goto ERROR;
+ }
+
+ // Create file
+ r = pakfire_file_create_from_archive_entry(file, pakfire, entry);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ if (r)
+ ERROR(pakfire, "Could not create file from path %s: %m\n", path);
+ if (entry)
+ archive_entry_free(entry);
+ if (reader)
+ archive_read_free(reader);
+
+ return r;
+}
+
int pakfire_file_create_from_archive_entry(struct pakfire_file** file, struct pakfire* pakfire,
struct archive_entry* entry) {
int r = pakfire_file_create(file, pakfire);
#include <archive_entry.h>
+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);
+ 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);
struct pakfire_file* file = NULL;
int r = 1;
- // Check if path is set
- if (!sourcepath) {
- errno = EINVAL;
- return 1;
- }
-
- // Use basename if path isn't set
- if (!path) {
- path = strrchr(sourcepath, '/');
- if (path)
- path++;
- }
-
- // Create a new file entry
- struct archive_entry* entry = archive_entry_new();
- if (!entry)
- return 1;
-
- // Set the source path
- archive_entry_copy_sourcepath(entry, sourcepath);
-
- // Set path in archive
- if (path)
- archive_entry_set_pathname(entry, path);
-
- // Read all attributes from file
- r = archive_read_disk_entry_from_file(packager->reader, entry, -1, NULL);
- if (r) {
- ERROR(packager->pakfire, "Could not read attributes from %s: %m\n", path);
- goto ERROR;
- }
-
- // Convert to file
- r = pakfire_file_create_from_archive_entry(&file, packager->pakfire, entry);
+ // Create file
+ r = pakfire_file_create_from_path(&file, packager->pakfire, sourcepath);
if (r)
goto ERROR;
+ // Assign a new path for inside the archive
+ if (path) {
+ r = pakfire_file_set_path(file, path);
+ if (r)
+ goto ERROR;
+ }
+
// Call the main function
r = pakfire_packager_add_file(packager, file);