aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2013-07-12 14:55:36 +0800
committerLAN-TW <lantw44@gmail.com>2013-07-12 14:55:36 +0800
commitbb257548a99b9027cef90e5acdefb3b7da9769fa (patch)
treed2b8de15502419724d36ee936529d8526d8a0d73
parentee50ed54fdeef30aa5b4b41763b5a6ac84a56627 (diff)
downloadgsoc2013-epiphany-bb257548a99b9027cef90e5acdefb3b7da9769fa.tar.gz
gsoc2013-epiphany-bb257548a99b9027cef90e5acdefb3b7da9769fa.tar.zst
gsoc2013-epiphany-bb257548a99b9027cef90e5acdefb3b7da9769fa.zip
Implement callback functions for archive_read_open
-rw-r--r--autoarchive/autoar-extract.c144
-rw-r--r--autoarchive/autoar-extract.h2
2 files changed, 122 insertions, 24 deletions
diff --git a/autoarchive/autoar-extract.c b/autoarchive/autoar-extract.c
index 2943058c6..ecaf20d8a 100644
--- a/autoarchive/autoar-extract.c
+++ b/autoarchive/autoar-extract.c
@@ -27,6 +27,8 @@
#include "autoar-extract.h"
+#include <gio/gio.h>
+#include <string.h>
#include <archive.h>
#include <archive_entry.h>
@@ -35,18 +37,23 @@ G_DEFINE_TYPE (AutoarExtract, autoar_extract, G_TYPE_OBJECT)
#define AUTOAR_EXTRACT_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), AUTOAR_TYPE_EXTRACT, AutoarExtractPrivate))
+#define BUFFER_SIZE (64 * 1024)
+
struct _AutoarExtractPrivate
{
char *source;
char *output;
- struct archive* ar_read;
-
guint64 size;
guint64 completed_size;
guint files;
guint completed_files;
+
+ GInputStream *istream;
+ void *buffer;
+ gssize buffer_size;
+ GError *error;
};
enum
@@ -221,24 +228,109 @@ autoar_extract_finalize (GObject *object)
arextract = AUTOAR_EXTRACT (object);
priv = arextract->priv;
- if (priv->source != NULL) {
- g_free (priv->source);
- priv->source = NULL;
- }
+ g_free (priv->source);
+ priv->source = NULL;
- if (priv->output != NULL) {
- g_free (priv->output);
- priv->output = NULL;
+ g_free (priv->output);
+ priv->output = NULL;
+
+ if (priv->istream != NULL) {
+ if (!g_input_stream_is_closed (priv->istream)) {
+ g_input_stream_close (priv->istream, NULL, NULL);
+ }
+ g_object_unref (priv->istream);
}
- if (priv->ar_read != NULL) {
- archive_read_free (priv->ar_read);
- priv->ar_read = NULL;
+ g_free (priv->buffer);
+ priv->buffer = NULL;
+
+ if (priv->error != NULL) {
+ g_error_free (priv->error);
+ priv->error = NULL;
}
G_OBJECT_CLASS (autoar_extract_parent_class)->finalize (object);
}
+static int
+libarchive_read_open_cb (struct archive *ar_read,
+ void *client_data)
+{
+ AutoarExtract *arextract;
+ GFile *file;
+ GFileInfo *fileinfo;
+
+ arextract = (AutoarExtract*)client_data;
+ if (arextract->priv->error != NULL) {
+ return ARCHIVE_FATAL;
+ }
+
+ file = g_file_new_for_commandline_arg (arextract->priv->source);
+
+ fileinfo = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL,
+ &(arextract->priv->error));
+ g_return_val_if_fail (arextract->priv->error == NULL, ARCHIVE_FATAL);
+
+ arextract->priv->size = g_file_info_get_size (fileinfo);
+ g_object_unref (fileinfo);
+
+ arextract->priv->istream = (GInputStream*)g_file_read (file,
+ NULL,
+ &(arextract->priv->error));
+ g_return_val_if_fail (arextract->priv->error == NULL, ARCHIVE_FATAL);
+
+ return ARCHIVE_OK;
+}
+
+static int
+libarchive_read_close_cb (struct archive *ar_read,
+ void *client_data)
+{
+ AutoarExtract *arextract;
+
+ arextract = (AutoarExtract*)client_data;
+ if (arextract->priv->error != NULL) {
+ return ARCHIVE_FATAL;
+ }
+
+ if (arextract->priv->istream != NULL) {
+ g_input_stream_close (arextract->priv->istream, NULL, NULL);
+ g_object_unref (arextract->priv->istream);
+ arextract->priv->istream = NULL;
+ }
+
+ return ARCHIVE_OK;
+}
+
+static ssize_t
+libarchive_read_read_cb (struct archive *ar_read,
+ void *client_data,
+ const void **buffer)
+{
+ AutoarExtract *arextract;
+ gssize read_size;
+
+ arextract = (AutoarExtract*)client_data;
+ if (arextract->priv->error != NULL) {
+ return -1;
+ }
+
+ *buffer = &(arextract->priv->buffer);
+ read_size = g_input_stream_read (arextract->priv->istream,
+ arextract->priv->buffer,
+ arextract->priv->buffer_size,
+ NULL,
+ &(arextract->priv->error));
+ g_return_val_if_fail (arextract->priv->error == NULL, -1);
+
+ arextract->priv->completed_size += read_size;
+
+ return read_size;
+}
+
/* Additional marshaller generated by glib-genmarshal
* Command: echo "VOID:DOUBLE,DOUBLE" | glib-genmarshal --header */
@@ -439,10 +531,10 @@ autoar_extract_class_init (AutoarExtractClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (AutoarExtractClass, error),
NULL, NULL,
- g_cclosure_marshal_VOID__INT,
+ g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE,
1,
- G_TYPE_INT);
+ G_TYPE_POINTER);
}
static void
@@ -456,23 +548,29 @@ autoar_extract_init (AutoarExtract *arextract)
priv->source = NULL;
priv->output = NULL;
- priv->ar_read = NULL;
-
priv->size = 0;
priv->completed_size = 0;
+ priv->files = 0;
priv->completed_files = 0;
+
+ priv->istream = NULL;
+ priv->buffer_size = BUFFER_SIZE;
+ priv->buffer = g_new (char, priv->buffer_size);
+ priv->error = NULL;
}
AutoarExtract*
autoar_extract_new (const char *source,
const char *output)
{
- AutoarExtract *arextract = g_object_new (AUTOAR_TYPE_EXTRACT,
- "source",
- source,
- "output",
- output,
- NULL);
- return arextract;
+ g_return_val_if_fail (source != NULL, NULL);
+ g_return_val_if_fail (output != NULL, NULL);
+
+ return g_object_new (AUTOAR_TYPE_EXTRACT,
+ "source",
+ source,
+ "output",
+ output,
+ NULL);
}
diff --git a/autoarchive/autoar-extract.h b/autoarchive/autoar-extract.h
index c76853107..2d93228f2 100644
--- a/autoarchive/autoar-extract.h
+++ b/autoarchive/autoar-extract.h
@@ -59,7 +59,7 @@ struct _AutoarExtractClass
gdouble fraction_files);
void (* completed) (AutoarExtract *arextract);
void (* error) (AutoarExtract *arextract,
- gint error_code);
+ GError* error);
};
GType autoar_extract_get_type (void) G_GNUC_CONST;
r timeout)trevor2004-03-3113-0/+14 * Update to KDE 3.2.1 / QT 3.3.1lofi2004-03-102-2/+1 * - rpm2cpio.pl need to be EXTRACT_DEPENDS otherwise it will not workpav2004-03-021-1/+1 * Update to KDE 3.2.0lofi2004-02-053-5/+6 * Add USE_GETTEXT and bump PORTREVISION.marcus2004-02-041-2/+2 * Now gettext 0.12.1 is gettext-old.trevor2004-01-241-1/+1 * Use the CPIO macro defined in bsd.port.mk.trevor2004-01-221-1/+1 * Use the SORT macro from bsd.port.mk.trevor2004-01-221-1/+1 * s/rpm2cpio/rpm2cpio.pl/ after the recent update of archivers/rpm2cpio (thenetchild2003-12-121-2/+2 * Another last minute change. Size/date stamp changes only.will2003-09-281-1/+1 * Upgrade to Qt 3.2.1 / KDE 3.1.4. See x11/kde3/Makefile rev 1.64 for details.will2003-09-181-2/+1 * Update this port from being based on the X11 R6.5.1 sources to R6.6.obrien2003-08-182-3/+4 * Remove the _POSIX_SOURCE handling to fix the building on 5-CURRENT.obrien2003-08-182-6/+2 * Update KDE to the latest official release, KDE 3.1.3lofi2003-07-292-1/+63 * Fix PLISTlioux2003-06-131-1/+17 * Update to KDE 3.1.2lioux2003-05-201-1/+1 * Add a NO_VIET_KDE knob to avoid the KDE I18N bits -- otherwise it is hard toobrien2003-05-091-0/+2 * BROKEN: Does not compilekris2003-05-071-0/+2 * Repo-move KDE I18N hebrew, hungarian, & vietnamese messages to theirwill2003-04-144-5/+72 * Clear moonlight beckons.ade2003-03-0730-15/+15 * Upgrade kde-i18n to 3.1. Note that the following modules did not get awill2003-01-292-38/+34 * Perl script to convert the text in the VIQR encoding to another Vietnameseobrien2002-11-136-0/+68 * o Rollback PORTCOMMENT modifications while this feature's implementationlioux2002-11-1126-26/+13 * Use PORTCOMMENT.obrien2002-11-0726-13/+26 * Add a missing directorykris2002-10-281-0/+1 * Get the dependencies correct for XF4.obrien2002-10-171-1/+1 * revert last commit. This builds fine here, and I've never seen oneobrien2002-10-171-2/+0 * Unmark broken. Please have the decentcy to notify the maintainer of a buildobrien2002-10-171-2/+0 * 1. Removed comments from pkg-plist files per will's request.alane2002-10-112-3/+27 * BROKEN: Does not compilekris2002-10-061-0/+2 * BROKEN: Missing dependencieskris2002-10-061-0/+2 * Don't gratuitously add -O.obrien2002-09-091-2/+2 * 'union wait' was depreciated by the time of Net/2.obrien2002-09-091-13/+24 * Catch up with lossage of 'union wait' in 5-CURRENT.obrien2002-09-092-21/+34 * Fix corrupted comment line.obrien2002-09-091-1/+1 * I have no idea what bsd.port.mk change broke this port, but be moreobrien2002-09-091-0/+1 * Update to 3.0.3. Not much changed here: [1] i18n PKGNAMEs converted towill2002-08-253-4/+4 * 1. Changed the lib depends on gettext to a build depends. This will meanalane2002-08-031-2/+2 * Bump PORTREVISION. KDE is fragile enough in its dependencies; we don'talane2002-08-021-0/+1 * Chase shlib rev of devel/gettextade2002-08-021-1/+1 * Fix MASTER_SITE_SUBDIR.will2002-07-101-1/+1 * Update to 3.0.2 -- full log available in ports/x11/kde3/Makefile,v 1.51.will2002-07-053-5/+12 * Upgrade to KDE 3.0.1. The delay in this upgrade is mainly due to thewill2002-06-163-2/+32 * Please welcome Qt3/KDE3 to our ports tree. This includes work since thewill2002-04-227-128/+154 * gettext upgrade uber-patch (stage 3)ade2002-04-131-1/+2 * Stage 1 of gettext update.ade2002-03-161-1/+1 * Add WWW.demon2001-12-281-0/+2 * Update to 2.2.2.demon2001-12-133-9/+16 * Note the standard these utilities conform to.obrien2001-11-2815-35/+133 * Unicode TrueType Font with UHoai Vietnamese encodingobrien2001-11-28