#include "config.h"
#include "ev-archive.h"
#include <archive.h>
#include <archive_entry.h>
#include <unarr/unarr.h>
#include <gio/gio.h>
Go to the source code of this file.
|
| G_DEFINE_TYPE (EvArchive, ev_archive, G_TYPE_OBJECT) |
|
static void | ev_archive_finalize (GObject *object) |
|
static void | ev_archive_class_init (EvArchiveClass *klass) |
|
EvArchive * | ev_archive_new (void) |
|
static void | libarchive_set_archive_type (EvArchive *archive, EvArchiveType archive_type) |
|
EvArchiveType | ev_archive_get_archive_type (EvArchive *archive) |
|
gboolean | ev_archive_set_archive_type (EvArchive *archive, EvArchiveType archive_type) |
|
gboolean | ev_archive_open_filename (EvArchive *archive, const char *path, GError **error) |
|
static gboolean | libarchive_read_next_header (EvArchive *archive, GError **error) |
|
gboolean | ev_archive_read_next_header (EvArchive *archive, GError **error) |
|
const char * | ev_archive_get_entry_pathname (EvArchive *archive) |
|
gint64 | ev_archive_get_entry_size (EvArchive *archive) |
|
gssize | ev_archive_read_data (EvArchive *archive, void *buf, gsize count, GError **error) |
|
void | ev_archive_reset (EvArchive *archive) |
|
static void | ev_archive_init (EvArchive *archive) |
|
#define BUFFER_SIZE (64 * 1024) |
static void ev_archive_class_init |
( |
EvArchiveClass * |
klass) | |
|
|
static |
Definition at line 68 of file ev-archive.c.
70 GObjectClass *object_class = (GObjectClass *) klass;
static void ev_archive_finalize |
( |
GObject * |
object) | |
|
|
static |
Definition at line 46 of file ev-archive.c.
48 EvArchive *archive = EV_ARCHIVE (
object);
50 switch (archive->type) {
53 g_clear_pointer (&archive->unarr_stream,
ar_close);
58 g_clear_pointer (&archive->libar, archive_free);
64 G_OBJECT_CLASS (ev_archive_parent_class)->finalize (
object);
const char* ev_archive_get_entry_pathname |
( |
EvArchive * |
archive) | |
|
Definition at line 221 of file ev-archive.c.
223 g_return_val_if_fail (EV_IS_ARCHIVE (archive), NULL);
226 switch (archive->type) {
228 g_assert_not_reached ();
230 g_return_val_if_fail (archive->unarr != NULL, NULL);
235 g_return_val_if_fail (archive->libar_entry != NULL, NULL);
236 return archive_entry_pathname (archive->libar_entry);
gint64 ev_archive_get_entry_size |
( |
EvArchive * |
archive) | |
|
Definition at line 243 of file ev-archive.c.
245 g_return_val_if_fail (EV_IS_ARCHIVE (archive), -1);
248 switch (archive->type) {
250 g_return_val_if_fail (archive->unarr != NULL, -1);
253 g_assert_not_reached ();
257 g_return_val_if_fail (archive->libar_entry != NULL, -1);
258 return archive_entry_size (archive->libar_entry);
static void ev_archive_init |
( |
EvArchive * |
archive) | |
|
|
static |
EvArchive* ev_archive_new |
( |
void |
) | |
|
gboolean ev_archive_open_filename |
( |
EvArchive * |
archive, |
|
|
const char * |
path, |
|
|
GError ** |
error |
|
) |
| |
Definition at line 128 of file ev-archive.c.
134 g_return_val_if_fail (EV_IS_ARCHIVE (archive),
FALSE);
136 g_return_val_if_fail (path != NULL,
FALSE);
138 switch (archive->type) {
140 g_assert_not_reached ();
143 if (archive->unarr_stream == NULL) {
144 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
145 "Error opening archive");
149 if (archive->unarr == NULL) {
150 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
151 "Error opening RAR archive");
158 r = archive_read_open_filename (archive->libar, path,
BUFFER_SIZE);
159 if (r != ARCHIVE_OK) {
160 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
161 "Error opening archive: %s", archive_error_string (archive->libar));
gssize ev_archive_read_data |
( |
EvArchive * |
archive, |
|
|
void * |
buf, |
|
|
gsize |
count, |
|
|
GError ** |
error |
|
) |
| |
Definition at line 265 of file ev-archive.c.
272 g_return_val_if_fail (EV_IS_ARCHIVE (archive), -1);
275 switch (archive->type) {
277 g_return_val_if_fail (archive->unarr != NULL, -1);
279 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
280 "Failed to decompress RAR data");
286 g_assert_not_reached ();
290 g_return_val_if_fail (archive->libar_entry != NULL, -1);
291 r = archive_read_data (archive->libar, buf, count);
293 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
294 "Failed to decompress data: %s", archive_error_string (archive->libar));
gboolean ev_archive_read_next_header |
( |
EvArchive * |
archive, |
|
|
GError ** |
error |
|
) |
| |
Definition at line 200 of file ev-archive.c.
203 g_return_val_if_fail (EV_IS_ARCHIVE (archive),
FALSE);
206 switch (archive->type) {
208 g_assert_not_reached ();
void ev_archive_reset |
( |
EvArchive * |
archive) | |
|
Definition at line 303 of file ev-archive.c.
305 g_return_if_fail (EV_IS_ARCHIVE (archive));
308 switch (archive->type) {
311 g_clear_pointer (&archive->unarr_stream,
ar_close);
316 g_clear_pointer (&archive->libar, archive_free);
320 g_assert_not_reached ();
gboolean ev_archive_set_archive_type |
( |
EvArchive * |
archive, |
|
|
EvArchiveType |
archive_type |
|
) |
| |
Definition at line 105 of file ev-archive.c.
108 g_return_val_if_fail (EV_IS_ARCHIVE (archive),
FALSE);
111 switch (archive_type) {
113 archive->type = archive_type;
121 g_assert_not_reached ();
G_DEFINE_TYPE |
( |
EvArchive |
, |
|
|
ev_archive |
, |
|
|
G_TYPE_OBJECT |
|
|
) |
| |
static gboolean libarchive_read_next_header |
( |
EvArchive * |
archive, |
|
|
GError ** |
error |
|
) |
| |
|
static |
Definition at line 171 of file ev-archive.c.
177 r = archive_read_next_header (archive->libar, &archive->libar_entry);
178 if (r != ARCHIVE_OK) {
179 if (r != ARCHIVE_EOF)
180 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
181 "Error reading archive: %s", archive_error_string (archive->libar));
185 if (archive_entry_filetype (archive->libar_entry) != AE_IFREG) {
186 g_debug (
"Skipping '%s' as it's not a regular file",
187 archive_entry_pathname (archive->libar_entry));
191 g_debug (
"At header for file '%s'", archive_entry_pathname (archive->libar_entry));
static void libarchive_set_archive_type |
( |
EvArchive * |
archive, |
|
|
EvArchiveType |
archive_type |
|
) |
| |
|
static |
Definition at line 82 of file ev-archive.c.
85 archive->type = archive_type;
86 archive->libar = archive_read_new ();
89 archive_read_support_format_zip (archive->libar);
91 archive_read_support_format_7zip (archive->libar);
93 archive_read_support_format_tar (archive->libar);