diff options
author | Carlos Soriano <csoriano@gnome.org> | 2016-04-12 15:51:27 +0200 |
---|---|---|
committer | Carlos Soriano <csoriano@gnome.org> | 2016-04-14 10:35:17 +0200 |
commit | 6f364bd8a2316bef4b029a4116148bfba0c68a66 (patch) | |
tree | 50ad9c987cffd77b447fc3b7ccd021de0ce9d24f | |
parent | f8ad3625ab5228d304007c3c44c7cab4eeec2d2a (diff) | |
download | nautilus-6f364bd8a2316bef4b029a4116148bfba0c68a66.tar.gz |
file: extract shared code for handling gone files on renaming
Just to make it cleaner.
https://bugzilla.gnome.org/show_bug.cgi?id=712620
-rw-r--r-- | libnautilus-private/nautilus-desktop-icon-file.c | 16 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 41 | ||||
-rw-r--r-- | 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 95a45e476..f08995c23 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 8e7d170e1..31965d05c 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 4c2645ab5..8623588a7 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. |