[PATCH] "Fixup" smb:/// entries



The attached patch is a crude hack (like most of smb:///) to "fix" the
issue that Nautilus messes up MIME types of smb://(/) contents all the
time (thus flipping directory and launcher MIME types), by constructing
separate "smb:///foo.desktop" and "smb://foo" entries. At the moment, I
think the issue is that Nautilus/GnomeVFS use some textual mechanism for
comparing URIs that ignores subsequent slashes, not realizing that
smb:///foo and smb://foo are different entities, and goes crazy when
trying to follow a link pointing to itself, pretending to be both a
directory and a launcher.

We don't really have a concept when "proto://" and "proto:///" are
considered identical, IIRC some modules even convert the URI to string
and skip these slashes in its handlers. From a user perspective, having
a root URI and a separate host construction seems unintuitive, so this
might actually be the more "correct" route.

Hopefully fixes http://bugzilla.gnome.org/show_bug.cgi?id=356093

-- 
Christian Neumair <chris gnome-de org>

Index: modules/smb-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/smb-method.c,v
retrieving revision 1.40
diff -u -p -r1.40 smb-method.c
--- modules/smb-method.c	30 May 2006 13:13:53 -0000	1.40
+++ modules/smb-method.c	25 Dec 2006 01:06:01 -0000
@@ -1442,7 +1442,17 @@ get_base_from_uri (GnomeVFSURI const *ur
 	return base;
 }
 
+static gchar *
+get_base_desktop_file_name_from_uri (GnomeVFSURI const *uri)
+{
+	char *base, *file_name;
+
+	base = get_base_from_uri (uri);
+	file_name = g_strconcat (base, ".desktop", NULL);
+	g_free (base);
 
+	return file_name;
+}
 
 typedef struct {
 	SMBCFILE *file;
@@ -1453,6 +1463,12 @@ typedef struct {
 	GnomeVFSFileOffset file_size;
 } FileHandle;
 
+
+#define TRUNCATE_DESKTOP_FILE_EXTENSION(str) \
+	if (g_str_has_suffix (str, ".desktop")) { \
+		*(str + strlen(str) - strlen(".desktop")) = '\0'; \
+	}
+
 static GnomeVFSResult
 do_open (GnomeVFSMethod *method,
 	 GnomeVFSMethodHandle **method_handle,
@@ -1491,7 +1507,9 @@ do_open (GnomeVFSMethod *method,
 		handle->is_data = TRUE;
 		handle->offset = 0;
 		unescaped_name = get_base_from_uri (uri);
+		TRUNCATE_DESKTOP_FILE_EXTENSION (unescaped_name);
 		name = gnome_vfs_uri_extract_short_path_name (uri);
+		TRUNCATE_DESKTOP_FILE_EXTENSION (name);
 		handle->file_data = get_workgroup_data (unescaped_name, name);
 		handle->file_size = strlen (handle->file_data);
 		g_free (unescaped_name);
@@ -1510,7 +1528,9 @@ do_open (GnomeVFSMethod *method,
 		handle->is_data = TRUE;
 		handle->offset = 0;
 		unescaped_name = get_base_from_uri (uri);
+		TRUNCATE_DESKTOP_FILE_EXTENSION (unescaped_name);
 		name = gnome_vfs_uri_extract_short_path_name (uri);
+		TRUNCATE_DESKTOP_FILE_EXTENSION (name);
 		handle->file_data = get_computer_data (unescaped_name, name);
 		handle->file_size = strlen (handle->file_data);
 		g_free (unescaped_name);
@@ -1787,7 +1807,7 @@ do_get_file_info (GnomeVFSMethod *method
 	    type == SMB_URI_WORKGROUP ||
 	    type == SMB_URI_SERVER ||
 	    type == SMB_URI_SHARE) {
-		file_info->name = get_base_from_uri (uri);
+		file_info->name = get_base_desktop_file_name_from_uri (uri);
 		file_info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE |
 			GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
 		file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY;
@@ -1812,7 +1832,7 @@ do_get_file_info (GnomeVFSMethod *method
 
 	if (type == SMB_URI_WORKGROUP_LINK ||
 	    type == SMB_URI_SERVER_LINK) {
-		file_info->name = get_base_from_uri (uri);
+		file_info->name = get_base_desktop_file_name_from_uri (uri);
 		file_info->valid_fields = file_info->valid_fields
 			| GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE
 			| GNOME_VFS_FILE_INFO_FIELDS_TYPE
@@ -1847,7 +1867,7 @@ do_get_file_info (GnomeVFSMethod *method
 		return actx.res;
 	
 	gnome_vfs_stat_to_file_info (file_info, &st);
-	file_info->name = get_base_from_uri (uri);
+	file_info->name = get_base_desktop_file_name_from_uri (uri);
 
 	file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
 	file_info->io_block_size = SMB_BLOCK_SIZE;
@@ -2081,7 +2101,8 @@ do_read_directory (GnomeVFSMethod *metho
 			/* workgroup link */
 			l = dh->workgroups;
 			dh->workgroups = g_list_remove_link (dh->workgroups, l);
-			file_info->name = l->data;
+			file_info->name = g_strconcat (l->data, ".desktop", NULL);
+			g_free (l->data);
 			g_list_free_1 (l);
 			
 			file_info->valid_fields =


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