aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2008-04-23 17:19:23 +0800
committerMilan Crha <mcrha@src.gnome.org>2008-04-23 17:19:23 +0800
commit9364fe50368e2c48b1987edd43c92c1ecd1cd8cd (patch)
tree571bfca73375b28c93caee273708e721de3e6c0d /e-util
parent0696568dc90ebe0c1eab8e9b58a8f32707d1663c (diff)
downloadgsoc2013-evolution-9364fe50368e2c48b1987edd43c92c1ecd1cd8cd.tar.gz
gsoc2013-evolution-9364fe50368e2c48b1987edd43c92c1ecd1cd8cd.tar.zst
gsoc2013-evolution-9364fe50368e2c48b1987edd43c92c1ecd1cd8cd.zip
** Fix for bug #529254
2008-04-23 Milan Crha <mcrha@redhat.com> ** Fix for bug #529254 * e-util/e-util.c: (e_write_file_uri): Save file properly. Handle either URI or filename. Return success or failure, not gint. * addressbook/gui/widgets/eab-gui-util.c: (save_it): Prototype and return value of e_write_file_uri has been changed. svn path=/trunk/; revision=35409
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog7
-rw-r--r--e-util/e-util.c43
-rw-r--r--e-util/e-util.h2
3 files changed, 29 insertions, 23 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 023c708dcc..af0027fd51 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-23 Milan Crha <mcrha@redhat.com>
+
+ ** Fix for bug #529254
+
+ * e-util.c: (e_write_file_uri): Save file properly.
+ Handle either URI or filename. Return success or failure, not gint.
+
2008-04-22 Matthew Barnes <mbarnes@redhat.com>
* Makefile.am:
diff --git a/e-util/e-util.c b/e-util/e-util.c
index f1bc8968c4..161a65789a 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -161,19 +161,29 @@ e_int_compare (gconstpointer x, gconstpointer y)
return (nx == ny) ? 0 : (nx < ny) ? -1 : 1;
}
-gint
+gboolean
e_write_file_uri (const gchar *filename, const gchar *data)
{
- gsize length = strlen (data);
- gssize bytes;
+ gboolean res;
+ gsize length;
GFile *file;
GOutputStream *stream;
GError *error = NULL;
- file = g_file_new_for_path (filename);
+ g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ length = strlen (data);
+
+ /* if it is uri, then create file for uri, otherwise for path */
+ if (strstr (filename, "://"))
+ file = g_file_new_for_uri (filename);
+ else
+ file = g_file_new_for_path (filename);
+
if (!file) {
g_warning ("Couldn't save item");
- return 1;
+ return FALSE;
}
stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
@@ -188,25 +198,14 @@ e_write_file_uri (const gchar *filename, const gchar *data)
if (error)
g_error_free (error);
- return 1;
+ return FALSE;
}
- while (length > 0) {
- bytes = g_output_stream_write_all (stream, data, length, NULL, NULL, &error);
- if (bytes > 0 && !error) {
- length -= bytes;
- data += bytes;
- } else {
- g_warning ("Couldn't save item%s%s", error ? ": " : "", error ? error->message : "");
+ res = g_output_stream_write_all (stream, data, length, NULL, NULL, &error);
- if (error)
- g_error_free (error);
-
- g_output_stream_close (stream, NULL, NULL);
- g_object_unref (stream);
-
- return 1;
- }
+ if (error) {
+ g_warning ("Couldn't save item: %s", error->message);
+ g_clear_error (&error);
}
g_output_stream_close (stream, NULL, &error);
@@ -217,7 +216,7 @@ e_write_file_uri (const gchar *filename, const gchar *data)
g_error_free (error);
}
- return 0;
+ return res;
}
/* Include build marshalers */
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 0f76e9e29e..5bdb218296 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -55,7 +55,7 @@ gint e_collate_compare (gconstpointer x,
gconstpointer y);
gint e_int_compare (gconstpointer x,
gconstpointer y);
-gint e_write_file_uri (const gchar *filename,
+gboolean e_write_file_uri (const gchar *filename,
const gchar *data);
/* This only makes a filename safe for usage as a filename.