[gnome-autoar] Add new GQuark for libarchive-related error
- From: Ting-Wei Lan <lantw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar] Add new GQuark for libarchive-related error
- Date: Thu, 29 Aug 2013 09:34:15 +0000 (UTC)
commit 6a3732447532036174879bd3f4e412dd6ddb94e6
Author: Ting-Wei Lan <lantw44 gmail com>
Date: Thu Aug 29 17:26:41 2013 +0800
Add new GQuark for libarchive-related error
G_DEFINE_QUARK is used to define GQuark. The old global variables are removed.
Error reported by libarchive use its own quark now. Quarks for autoar-extract
and autoar-create are only used for error occurred within gnome-autoar.
gnome-autoar/autoar-common.c | 12 ++++++------
gnome-autoar/autoar-common.h | 10 ++++++----
gnome-autoar/autoar-create.c | 12 +++++-------
gnome-autoar/autoar-create.h | 5 ++++-
gnome-autoar/autoar-extract.c | 14 ++++++--------
gnome-autoar/autoar-extract.h | 5 ++++-
6 files changed, 31 insertions(+), 27 deletions(-)
---
diff --git a/gnome-autoar/autoar-common.c b/gnome-autoar/autoar-common.c
index 39cc554..5feda50 100644
--- a/gnome-autoar/autoar-common.c
+++ b/gnome-autoar/autoar-common.c
@@ -42,6 +42,8 @@ struct _AutoarCommonSignalData
GQuark detail;
};
+G_DEFINE_QUARK (libarchive-quark, autoar_common_libarchive)
+
char*
autoar_common_get_filename_extension (const char *filename)
{
@@ -164,12 +166,11 @@ autoar_common_g_signal_emit (gpointer instance,
}
GError*
-autoar_common_g_error_new_a (GQuark quark,
- struct archive *a,
+autoar_common_g_error_new_a (struct archive *a,
const char *pathname)
{
GError *newerror;
- newerror = g_error_new (quark,
+ newerror = g_error_new (AUTOAR_LIBARCHIVE_ERROR,
archive_errno (a),
"%s%s%s%s",
pathname != NULL ? "\'" : "",
@@ -180,9 +181,8 @@ autoar_common_g_error_new_a (GQuark quark,
}
GError*
-autoar_common_g_error_new_a_entry (GQuark quark,
- struct archive *a,
+autoar_common_g_error_new_a_entry (struct archive *a,
struct archive_entry *entry)
{
- return autoar_common_g_error_new_a (quark, a, archive_entry_pathname (entry));
+ return autoar_common_g_error_new_a (a, archive_entry_pathname (entry));
}
diff --git a/gnome-autoar/autoar-common.h b/gnome-autoar/autoar-common.h
index 3c6d8af..59518bf 100644
--- a/gnome-autoar/autoar-common.h
+++ b/gnome-autoar/autoar-common.h
@@ -37,6 +37,10 @@
G_BEGIN_DECLS
+#define AUTOAR_LIBARCHIVE_ERROR autoar_common_libarchive_quark()
+
+GQuark autoar_common_libarchive_quark (void);
+
char* autoar_common_get_basename_remove_extension (const char *filename);
char* autoar_common_get_filename_extension (const char *filename);
@@ -46,11 +50,9 @@ void autoar_common_g_signal_emit (gpointer instance,
GQuark detail,
...);
-GError* autoar_common_g_error_new_a (GQuark quark,
- struct archive *a,
+GError* autoar_common_g_error_new_a (struct archive *a,
const char *pathname);
-GError* autoar_common_g_error_new_a_entry (GQuark quark,
- struct archive *a,
+GError* autoar_common_g_error_new_a_entry (struct archive *a,
struct archive_entry *entry);
G_END_DECLS
diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c
index 8f72607..97c179f 100644
--- a/gnome-autoar/autoar-create.c
+++ b/gnome-autoar/autoar-create.c
@@ -39,6 +39,7 @@
#include <unistd.h>
G_DEFINE_TYPE (AutoarCreate, autoar_create, G_TYPE_OBJECT)
+G_DEFINE_QUARK (autoar-create, autoar_create)
#define AUTOAR_CREATE_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), AUTOAR_TYPE_CREATE, AutoarCreatePrivate))
@@ -99,7 +100,6 @@ enum
};
static guint autoar_create_signals[LAST_SIGNAL] = { 0 };
-GQuark autoar_create_quark;
static void
autoar_create_get_property (GObject *object,
@@ -482,7 +482,7 @@ autoar_create_do_write_data (AutoarCreate *arcreate,
while ((r = archive_write_header (priv->a, entry)) == ARCHIVE_RETRY);
if (r == ARCHIVE_FATAL) {
if (priv->error == NULL)
- priv->error = autoar_common_g_error_new_a_entry (autoar_create_quark, priv->a, entry);
+ priv->error = autoar_common_g_error_new_a_entry (priv->a, entry);
return;
}
@@ -536,7 +536,7 @@ autoar_create_do_write_data (AutoarCreate *arcreate,
if (written_actual < 0 || written_try >= ARCHIVE_WRITE_RETRY_TIMES) {
if (priv->error == NULL)
- priv->error = autoar_common_g_error_new_a_entry (autoar_create_quark, priv->a, entry);
+ priv->error = autoar_common_g_error_new_a_entry (priv->a, entry);
return;
}
g_debug ("autoar_create_do_write_data: write data OK");
@@ -805,8 +805,6 @@ autoar_create_class_init (AutoarCreateClass *klass)
g_type_class_add_private (klass, sizeof (AutoarCreatePrivate));
- autoar_create_quark = g_quark_from_static_string ("autoar-create");
-
object_class->get_property = autoar_create_get_property;
object_class->set_property = autoar_create_set_property;
object_class->dispose = autoar_create_dispose;
@@ -1145,7 +1143,7 @@ autoar_create_run (AutoarCreate *arcreate)
libarchive_write_close_cb);
if (r != ARCHIVE_OK) {
if (priv->error == NULL)
- priv->error = autoar_common_g_error_new_a (autoar_create_quark, priv->a, NULL);
+ priv->error = autoar_common_g_error_new_a (priv->a, NULL);
autoar_create_signal_error (arcreate);
return;
}
@@ -1217,7 +1215,7 @@ autoar_create_run (AutoarCreate *arcreate)
r = archive_write_close (priv->a);
if (r != ARCHIVE_OK) {
if (arcreate->priv->error == NULL)
- priv->error = autoar_common_g_error_new_a (autoar_create_quark, priv->a, NULL);
+ priv->error = autoar_common_g_error_new_a (priv->a, NULL);
return;
}
diff --git a/gnome-autoar/autoar-create.h b/gnome-autoar/autoar-create.h
index 4f40fe7..0d64993 100644
--- a/gnome-autoar/autoar-create.h
+++ b/gnome-autoar/autoar-create.h
@@ -66,7 +66,10 @@ struct _AutoarCreateClass
GError *error);
};
-extern GQuark autoar_create_quark;
+#define AUTOAR_CREATE_ERROR autoar_create_quark()
+
+GQuark autoar_create_quark (void);
+
GType autoar_create_get_type (void) G_GNUC_CONST;
AutoarCreate* autoar_create_new (AutoarPref *arpref,
diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c
index 03a14c0..507eb5c 100644
--- a/gnome-autoar/autoar-extract.c
+++ b/gnome-autoar/autoar-extract.c
@@ -54,6 +54,7 @@
G_DEFINE_TYPE (AutoarExtract, autoar_extract, G_TYPE_OBJECT)
+G_DEFINE_QUARK (autoar-extract, autoar_extract)
#define AUTOAR_EXTRACT_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), AUTOAR_TYPE_EXTRACT, AutoarExtractPrivate))
@@ -145,7 +146,6 @@ enum
};
static guint autoar_extract_signals[LAST_SIGNAL] = { 0 };
-GQuark autoar_extract_quark;
static void
autoar_extract_get_property (GObject *object,
@@ -1114,8 +1114,6 @@ autoar_extract_class_init (AutoarExtractClass *klass)
g_type_class_add_private (klass, sizeof (AutoarExtractPrivate));
- autoar_extract_quark = g_quark_from_static_string ("autoar-extract");
-
object_class->get_property = autoar_extract_get_property;
object_class->set_property = autoar_extract_set_property;
object_class->dispose = autoar_extract_dispose;
@@ -1497,12 +1495,12 @@ autoar_extract_step_scan_toplevel (AutoarExtract *arextract) {
r = libarchive_create_read_object (TRUE, arextract, &a);
if (priv->error == NULL) {
if (r != ARCHIVE_OK) {
- priv->error = autoar_common_g_error_new_a (autoar_extract_quark, a, priv->source);
+ priv->error = autoar_common_g_error_new_a (a, priv->source);
} else if (archive_filter_count (a) <= 1){
/* If we only use raw format and filter count is one, libarchive will
* not do anything except for just copying the source file. We do not
* want this thing to happen because it does unnecesssary copying. */
- priv->error = g_error_new (autoar_extract_quark, NOT_AN_ARCHIVE_ERRNO,
+ priv->error = g_error_new (AUTOAR_EXTRACT_ERROR, NOT_AN_ARCHIVE_ERRNO,
"\'%s\': %s", priv->source, "not an archive");
}
}
@@ -1561,7 +1559,7 @@ autoar_extract_step_scan_toplevel (AutoarExtract *arextract) {
if (r != ARCHIVE_EOF) {
if (priv->error == NULL) {
- priv->error = autoar_common_g_error_new_a (autoar_extract_quark, a, priv->source);
+ priv->error = autoar_common_g_error_new_a (a, priv->source);
}
g_free (pathname_prefix);
archive_read_free (a);
@@ -1666,7 +1664,7 @@ autoar_extract_step_extract (AutoarExtract *arextract) {
r = libarchive_create_read_object (priv->use_raw_format, arextract, &a);
if (r != ARCHIVE_OK) {
if (priv->error == NULL) {
- priv->error = autoar_common_g_error_new_a (autoar_extract_quark, a, priv->source);
+ priv->error = autoar_common_g_error_new_a (a, priv->source);
}
archive_read_free (a);
return;
@@ -1727,7 +1725,7 @@ autoar_extract_step_extract (AutoarExtract *arextract) {
if (r != ARCHIVE_EOF) {
if (priv->error == NULL) {
- priv->error = autoar_common_g_error_new_a (autoar_extract_quark, a, priv->source);
+ priv->error = autoar_common_g_error_new_a (a, priv->source);
}
archive_read_free (a);
return;
diff --git a/gnome-autoar/autoar-extract.h b/gnome-autoar/autoar-extract.h
index 5120154..31b8e84 100644
--- a/gnome-autoar/autoar-extract.h
+++ b/gnome-autoar/autoar-extract.h
@@ -68,7 +68,10 @@ struct _AutoarExtractClass
GError *error);
};
-extern GQuark autoar_extract_quark;
+#define AUTOAR_EXTRACT_ERROR autoar_extract_quark()
+
+GQuark autoar_extract_quark (void);
+
GType autoar_extract_get_type (void) G_GNUC_CONST;
AutoarExtract *autoar_extract_new (const char *source,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]