summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2016-04-12 15:51:27 +0200
committerCarlos Soriano <csoriano@gnome.org>2016-04-12 16:25:52 +0200
commit52f30a9c84035d4b797d785dbbb4ecfd04c86f5f (patch)
tree51741c3a85b3ae94d559ebc627ddacaa0a121156
parentfeab581803bb5e5d32dd8319b6bf6b81aebbd853 (diff)
downloadnautilus-52f30a9c84035d4b797d785dbbb4ecfd04c86f5f.tar.gz
file: extract shared code for handling gone files on renaming
Just to make it cleaner.
-rw-r--r--libnautilus-private/nautilus-desktop-icon-file.c16
-rw-r--r--libnautilus-private/nautilus-file.c41
-rw-r--r--libnautilus-private/nautilus-file.h7
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.