[gnome-photos/wip/rishi/misc-fixes: 18/24] Use make_directory_with_parents wrapper that ignores ERROR_EXIST



commit 42b1315751b9ba6a52a10ed655a03f13ccca27bf
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Dec 22 20:04:40 2015 +0100

    Use make_directory_with_parents wrapper that ignores ERROR_EXIST

 src/photos-application.c |   18 ++++--------------
 src/photos-utils.c       |   23 +++++++++++++++++++++++
 src/photos-utils.h       |    2 ++
 3 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index e0d8ae5..7f70d95 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -926,23 +926,13 @@ photos_application_save (PhotosApplication *self)
   pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
   parent_path = g_build_filename (pictures_path, PHOTOS_EXPORT_SUBPATH, NULL);
   parent = g_file_new_for_path (parent_path);
-  g_file_make_directory_with_parents (parent, NULL, &error);
-  if (error != NULL)
+  if (!photos_utils_make_directory_with_parents (parent, NULL, &error))
     {
-      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
-        {
-          g_error_free (error);
-          goto carry_on;
-        }
-      else
-        {
-          g_warning ("Unable to create %s: %s", parent_path, error->message);
-          g_error_free (error);
-          goto out;
-        }
+      g_warning ("Unable to create %s: %s", parent_path, error->message);
+      g_error_free (error);
+      goto out;
     }
 
- carry_on:
   now = g_date_time_new_now_local ();
   origin = g_date_time_format (now, "%Y-%m-%d %H-%M-%S");
 
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 13d61f5..e9f9f60 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1017,6 +1017,29 @@ photos_utils_icon_from_rdf_type (const gchar *type)
 }
 
 
+gboolean
+photos_utils_make_directory_with_parents (GFile *file, GCancellable *cancellable, GError **error)
+{
+  GError *local_error = NULL;
+  gboolean ret_val;
+
+  ret_val = g_file_make_directory_with_parents (file, cancellable, &local_error);
+  if (local_error != NULL)
+    {
+      if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+        {
+          g_clear_error (&local_error);
+          ret_val = TRUE;
+        }
+    }
+
+  if (local_error != NULL)
+    g_propagate_error (error, local_error);
+
+  return ret_val;
+}
+
+
 GQuark
 photos_utils_orientation_bottom_quark (void)
 {
diff --git a/src/photos-utils.h b/src/photos-utils.h
index b830dde..e706619 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -136,6 +136,8 @@ GList           *photos_utils_get_urns_from_paths         (GList *paths, GtkTree
 
 GIcon           *photos_utils_icon_from_rdf_type          (const gchar *type);
 
+gboolean         photos_utils_make_directory_with_parents (GFile *file, GCancellable *cancellable, GError 
**error);
+
 GQuark           photos_utils_orientation_bottom_quark    (void);
 
 GQuark           photos_utils_orientation_left_quark      (void);


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