[PATCH] Fix symlink trashing (yet again)



It turns out that my last symlink handling fix only worked for broken
symlinks to other file systems.

gnome_vfs_find_directory resolves symlinks before determining the trash
volume and will therefore return the trash directory for the link
target, not the symlink itself. Because we've obviously used these
GnomeVFS resolution semantics for a long time, I don't think we should
change them.

The attached version ensures that symlinks can always be trashed, no
matter where they point, by finding the trash using the source URIs
parent whenever possible.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.197
diff -u -p -r1.197 nautilus-file-operations.c
--- libnautilus-private/nautilus-file-operations.c	19 Sep 2005 15:50:57 -0000	1.197
+++ libnautilus-private/nautilus-file-operations.c	9 Oct 2005 14:12:45 -0000
@@ -1,4 +1,3 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
 /* nautilus-file-operations.c - Nautilus file operations.
 
@@ -1857,20 +1856,27 @@ nautilus_file_operations_copy_move (cons
 		/* Note: this could be null if we're e.g. copying the top level file of a web site */
 		source_dir_uri = gnome_vfs_uri_get_parent (source_uri);
 		target_uri = NULL;
-		if (target_dir != NULL) {
-			if (target_is_trash) {
-				result = gnome_vfs_find_directory (source_uri, GNOME_VFS_DIRECTORY_KIND_TRASH,
-								   &target_dir_uri, FALSE, FALSE, 0777);
-				if (result == GNOME_VFS_ERROR_NOT_FOUND && source_dir_uri != NULL) {
-					/* source_uri may be a broken symlink */
-					result = gnome_vfs_find_directory (source_dir_uri, GNOME_VFS_DIRECTORY_KIND_TRASH,
-									   &target_dir_uri, FALSE, FALSE, 0777);
-				}
+		if (target_is_trash) {
+			GnomeVFSURI *trash_find_uri;
 
-				result = GNOME_VFS_OK;
-			}
-			if (target_dir_uri != NULL) {
+			/* source_uri may be a symlink, which is resolved when finding the trash directory.
+			 * Therefore, we use its parent dir if available */
+			trash_find_uri = source_dir_uri != NULL ? source_dir_uri : source_uri;
+
+			result = gnome_vfs_find_directory (trash_find_uri,
+							   GNOME_VFS_DIRECTORY_KIND_TRASH,
+							   &target_dir_uri, FALSE, FALSE, 0777);
+
+			if (result == GNOME_VFS_OK) {
 				target_uri = append_basename (target_dir_uri, source_uri);
+			} else {
+				char *trash_find_text_uri;
+
+				trash_find_text_uri = gnome_vfs_uri_to_string (trash_find_uri, GNOME_VFS_URI_HIDE_NONE);
+				g_message ("Unable to find trash for \"%s\": %s",
+					   trash_find_text_uri,
+					   gnome_vfs_result_to_string (result));
+				g_free (trash_find_text_uri);
 			}
 		} else {
 			/* duplication */

Attachment: signature.asc
Description: This is a digitally signed message part



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