// Use the libarchive entry to store common attributes
struct archive_entry* entry;
+ // File Descriptor
+ int fd;
+
// Capabilities
cap_t caps;
// Initialize reference counter
f->nrefs = 1;
+ // Initialize file descriptor
+ f->fd = -EBADF;
+
// Create a new archive entry
f->entry = archive_entry_new();
if (!f->entry) {
}
static void pakfire_file_free(struct pakfire_file* file) {
+ if (file->fd >= 0)
+ close(file->fd);
+
// Free capabilities
if (file->caps)
cap_free(file->caps);
return 0;
}
+// File Descriptor
+
+int pakfire_file_get_fd(struct pakfire_file* file) {
+ return file->fd;
+}
+
+int pakfire_file_set_fd(struct pakfire_file* file, int fd) {
+ // Close any previously assigned file descriptors
+ if (file->fd >= 0)
+ close(file->fd);
+
+ // Duplicate the file descriptor
+ file->fd = dup(fd);
+ if (file->fd < 0) {
+ CTX_ERROR(file->ctx, "Could not duplicate file descriptor: %m\n");
+ return -errno;
+ }
+
+ return 0;
+}
+
#define pakfire_file_strmode(file, buffer) \
__pakfire_file_strmode(file, buffer, sizeof(buffer))
PAKFIRE_FILE_RUNTIME_LINKER = (1 << 14),
};
+int pakfire_file_get_fd(struct pakfire_file* file);
+int pakfire_file_set_fd(struct pakfire_file* file, int fd);
+
int pakfire_file_has_payload(struct pakfire_file* file);
int pakfire_file_read(struct pakfire_file* file, struct archive* reader, const char* path);