[gthumb] do not allow to rename the catalog if the new name is already used



commit 96a3c6dae48da8147b01d075ca7fa7291e10bab0
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Dec 11 17:48:59 2011 +0100

    do not allow to rename the catalog if the new name is already used

 extensions/catalogs/gth-file-source-catalogs.c |   38 ++++++++++++++---------
 1 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/extensions/catalogs/gth-file-source-catalogs.c b/extensions/catalogs/gth-file-source-catalogs.c
index 3db9721..1814093 100644
--- a/extensions/catalogs/gth-file-source-catalogs.c
+++ b/extensions/catalogs/gth-file-source-catalogs.c
@@ -432,6 +432,7 @@ gth_file_source_catalogs_rename (GthFileSource *file_source,
 		GFile *gio_new_file;
 		char  *data;
 		gsize  size;
+		GFileOutputStream *fstream;
 
 		uri = g_file_get_uri (file);
 		clean_name = _g_filename_clear_for_file (edit_name);
@@ -442,21 +443,28 @@ gth_file_source_catalogs_rename (GthFileSource *file_source,
 
 		gio_new_file = gth_catalog_file_to_gio_file (new_file);
 		data = gth_catalog_to_data (catalog, &size);
-		if (g_write_file (gio_new_file,
-				  FALSE,
-				  G_FILE_CREATE_NONE,
-				  data,
-				  size,
-				  gth_file_source_get_cancellable (file_source),
-				  &error))
-		{
-			GFile *gio_old_file;
-
-			gio_old_file = gth_catalog_file_to_gio_file (file);
-			if (g_file_delete (gio_old_file, gth_file_source_get_cancellable (file_source), &error))
-				gth_monitor_file_renamed (gth_main_get_default_monitor (), file, new_file);
-
-			g_object_unref (gio_old_file);
+		fstream = g_file_create (gio_new_file,
+					 G_FILE_CREATE_NONE,
+					 gth_file_source_get_cancellable (file_source),
+					 &error);
+		if (fstream != NULL) {
+		     if (g_output_stream_write_all (G_OUTPUT_STREAM (fstream),
+						    data,
+						    size,
+						    NULL,
+						    gth_file_source_get_cancellable (file_source),
+						    &error))
+		     {
+			     GFile *gio_old_file;
+
+			     gio_old_file = gth_catalog_file_to_gio_file (file);
+			     if (g_file_delete (gio_old_file, gth_file_source_get_cancellable (file_source), &error))
+				     gth_monitor_file_renamed (gth_main_get_default_monitor (), file, new_file);
+
+			     g_object_unref (gio_old_file);
+		     }
+
+		     g_object_unref (fstream);
 		}
 
 		g_free (data);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]