[nautilus/origin/wip/desktop-split-nofonclicts: 19/26] file: extract shared code for handling gone files on renaming



commit 52f30a9c84035d4b797d785dbbb4ecfd04c86f5f
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Apr 12 15:51:27 2016 +0200

    file: extract shared code for handling gone files on renaming
    
    Just to make it cleaner.

 libnautilus-private/nautilus-desktop-icon-file.c |   16 ++-------
 libnautilus-private/nautilus-file.c              |   41 ++++++++++++++-------
 libnautilus-private/nautilus-file.h              |    7 ++++
 3 files changed, 37 insertions(+), 27 deletions(-)
---
diff --git a/libnautilus-private/nautilus-desktop-icon-file.c 
b/libnautilus-private/nautilus-desktop-icon-file.c
index 95a45e4..f08995c 100644
--- a/libnautilus-private/nautilus-desktop-icon-file.c
+++ b/libnautilus-private/nautilus-desktop-icon-file.c
@@ -386,19 +386,9 @@ real_rename (NautilusFile                  *file,
         * We need to check this here because there may be a new
         * file with the same name.
         */
-       if (nautilus_file_is_gone (file)) {
-               /* Claim that something changed even if the rename
-                * failed. This makes it easier for some clients who
-                * see the "reverting" to the old name as "changing
-                * back".
-                */
-               nautilus_file_changed (file);
-               error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
-                                    _("File not found"));
-               (* callback) (file, NULL, error, callback_data);
-               g_error_free (error);
-               return;
-       }
+        if (nautilus_file_rename_handle_file_gone (file, callback, callback_data)) {
+                return;
+        }
 
        link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
        old_name = nautilus_file_get_display_name (file);
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 8e7d170..31965d0 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -1811,6 +1811,30 @@ nautilus_file_rename (NautilusFile                  *file,
                                                                  callback_data);
 }
 
+gboolean
+nautilus_file_rename_handle_file_gone (NautilusFile                  *file,
+                                       NautilusFileOperationCallback  callback,
+                                       gpointer                       callback_data)
+{
+       GError *error;
+
+       if (nautilus_file_is_gone (file)) {
+               /* Claim that something changed even if the rename
+                * failed. This makes it easier for some clients who
+                * see the "reverting" to the old name as "changing
+                * back".
+                */
+               nautilus_file_changed (file);
+               error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                                    _("File not found"));
+               (* callback) (file, NULL, error, callback_data);
+               g_error_free (error);
+               return TRUE;
+       }
+
+  return FALSE;
+}
+
 static void
 real_rename (NautilusFile                  *file,
              const char                    *new_name,
@@ -1847,20 +1871,9 @@ real_rename (NautilusFile                  *file,
         * We need to check this here because there may be a new
         * file with the same name.
         */
-       if (nautilus_file_is_gone (file)) {
-               /* Claim that something changed even if the rename
-                * failed. This makes it easier for some clients who
-                * see the "reverting" to the old name as "changing
-                * back".
-                */
-               nautilus_file_changed (file);
-               error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
-                                    _("File not found"));
-               (* callback) (file, NULL, error, callback_data);
-               g_error_free (error);
-               return;
-       }
-
+        if (nautilus_file_rename_handle_file_gone (file, callback, callback_data)) {
+                return;
+        }
        /* Test the name-hasn't-changed case explicitly, for two reasons.
         * (1) rename returns an error if new & old are same.
         * (2) We don't want to send file-changed signal if nothing changed.
diff --git a/libnautilus-private/nautilus-file.h b/libnautilus-private/nautilus-file.h
index 4c2645a..8623588 100644
--- a/libnautilus-private/nautilus-file.h
+++ b/libnautilus-private/nautilus-file.h
@@ -334,6 +334,13 @@ void                    nautilus_file_cancel                            (Nautilu
  */
 gboolean                nautilus_file_is_gone                           (NautilusFile                   
*file);
 
+/* Used in subclasses that handles the rename of a file. This handles the case
+ * when the file is gone. If this returns TRUE, simply do nothing
+ */
+gboolean                nautilus_file_rename_handle_file_gone           (NautilusFile                   
*file,
+                                                                         NautilusFileOperationCallback   
callback,
+                                                                         gpointer                        
callback_data);
+
 /* Return true if this file is not confirmed to have ever really
  * existed. This is true when the NautilusFile object has been created, but no I/O
  * has yet confirmed the existence of a file by that name.


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