Pakfire pakfire;
int nrefs;
- PakfirePackage package;
char path[PATH_MAX];
+ FILE* f;
+ PakfirePackage package;
// metadata
unsigned int format;
int nrefs;
};
-static int archive_open(PakfireArchive archive, struct archive** a) {
+/*
+ A helper function to close the archive and reset our data structures
+*/
+static void close_archive(PakfireArchive archive, struct archive* a) {
+ archive_read_free(a);
+
+ // Rewind the file descriptor
+ rewind(archive->f);
+}
+
+/*
+ A helper function that opens the archive for reading
+*/
+static int open_archive(PakfireArchive archive, struct archive** a) {
*a = archive_read_new();
if (!*a)
return ENOMEM;
archive_read_support_format_tar(*a);
// Try opening the archive file
- int r = archive_read_open_filename(*a, archive->path, 8192);
+ int r = archive_read_open_FILE(*a, archive->f);
if (r) {
ERROR(archive->pakfire, "Could not open archive %s: %s\n",
archive->path, archive_error_string(*a));
- archive_read_free(*a);
- *a = NULL;
- return r;
+ goto ERROR;
}
+ // Success
return 0;
+
+ERROR:
+ close_archive(archive, *a);
+ *a = NULL;
+
+ return r;
}
static int find_archive_entry(struct archive_entry** entry, struct archive* a, const char* filename) {
static void pakfire_archive_free(PakfireArchive archive) {
DEBUG(archive->pakfire, "Releasing archive at %p\n", archive);
+ // Close the file
+ if (archive->f)
+ fclose(archive->f);
+
// Free all checksums
pakfire_archive_free_chksums(archive);
return 0;
// Open the archive
- int r = archive_open(archive, &a);
+ int r = open_archive(archive, &a);
if (r)
goto ERROR;
struct archive* a;
// Open the archive file
- int r = archive_open(archive, &a);
+ int r = open_archive(archive, &a);
if (r)
return r;
// Store path
pakfire_string_set(archive->path, path);
+ // Open the file (and keep the file descriptor open)
+ archive->f = fopen(archive->path, "r");
+ if (!archive->f)
+ return 1;
+
// Open the archive file for reading.
struct archive* a = NULL;
- int r = archive_open(archive, &a);
+ int r = open_archive(archive, &a);
if (r)
goto ERROR;
while (*filename == '/')
filename++;
- int r = archive_open(archive, &a);
+ int r = open_archive(archive, &a);
if (r)
goto ERROR;
goto ERROR;
// Open the archive
- r = archive_open(archive, &a);
+ r = open_archive(archive, &a);
if (r)
goto ERROR;
int r;
// Open the archive
- r = archive_open(archive, &a);
+ r = open_archive(archive, &a);
if (r)
goto ERROR;
// Open the archive file
struct archive* a;
- int r = archive_open(archive, &a);
+ int r = open_archive(archive, &a);
if (r)
return PAKFIRE_ARCHIVE_VERIFY_ERROR;