rhythmbox r5751 - in trunk: . lib sources



Author: teuf
Date: Sun Jun 15 12:30:48 2008
New Revision: 5751
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=5751&view=rev

Log:
When copying to a DAP, sanitize filenames so that they are valid on the destination FS


Modified:
   trunk/ChangeLog
   trunk/lib/rb-file-helpers.c
   trunk/lib/rb-file-helpers.h
   trunk/lib/rb-util.c
   trunk/lib/rb-util.h
   trunk/sources/rb-removable-media-source.c

Modified: trunk/lib/rb-file-helpers.c
==============================================================================
--- trunk/lib/rb-file-helpers.c	(original)
+++ trunk/lib/rb-file-helpers.c	Sun Jun 15 12:30:48 2008
@@ -43,6 +43,7 @@
 
 #include "rb-file-helpers.h"
 #include "rb-debug.h"
+#include "rb-util.h"
 
 static GHashTable *files = NULL;
 
@@ -1269,3 +1270,46 @@
 	}
 }
 
+char *
+rb_sanitize_uri_for_filesystem(gchar *uri)
+{
+	gchar *filesystem = rb_uri_get_filesystem_type(uri);
+	gchar *sane_uri = NULL;
+
+	if (!filesystem)
+		return g_strdup(uri);
+
+	if (!strcmp(filesystem, "fat") ||
+	    !strcmp(filesystem, "vfat") ) {
+	    	gchar *hostname = NULL;
+		GError *error = NULL;
+	    	gchar *full_path = g_filename_from_uri(uri, &hostname, &error);
+
+		if (error) {
+			g_error_free(error);
+			g_free(filesystem);
+			g_free(full_path);
+			return g_strdup(uri);
+		}
+
+		g_strdelimit (full_path, "\"", '\'');
+		g_strdelimit (full_path, ":|<>*?\\", '_');
+
+		/* create a new uri from this */
+		sane_uri = g_filename_to_uri(full_path, hostname, &error);
+
+		g_free(hostname);
+		g_free(full_path);
+
+		if (error) {
+			g_error_free(error);
+			g_free(filesystem);
+			return g_strdup(uri);
+		}
+	}
+
+	/* add workarounds for other filesystems limitations here */
+
+	g_free(filesystem);
+	return sane_uri ? sane_uri : g_strdup(uri);
+}

Modified: trunk/lib/rb-file-helpers.h
==============================================================================
--- trunk/lib/rb-file-helpers.h	(original)
+++ trunk/lib/rb-file-helpers.h	Sun Jun 15 12:30:48 2008
@@ -79,6 +79,8 @@
 void		rb_file_helpers_init	(void);
 void		rb_file_helpers_shutdown(void);
 
+char *		rb_sanitize_uri_for_filesystem(gchar *uri);
+
 G_END_DECLS
 
 #endif /* __RB_FILE_HELPERS_H */

Modified: trunk/lib/rb-util.c
==============================================================================
--- trunk/lib/rb-util.c	(original)
+++ trunk/lib/rb-util.c	Sun Jun 15 12:30:48 2008
@@ -376,6 +376,56 @@
 	return mount_point;
 }
 
+gchar *
+rb_uri_get_filesystem_type(const char *uri)
+{
+	GnomeVFSVolume *volume = NULL;
+	GnomeVFSVolumeMonitor *monitor = NULL;
+	gchar *mount_point_uri = NULL, *mount_point_path = NULL;
+	gchar *fstype = NULL;
+	GError *error = NULL;
+	
+	g_return_val_if_fail(uri != NULL, NULL);
+
+	monitor = gnome_vfs_get_volume_monitor ();
+	if (monitor == NULL) {
+		goto error;
+	}
+
+	mount_point_uri = rb_uri_get_mount_point(uri);
+	if (mount_point_uri == NULL) {
+		goto error;
+	}
+	
+	mount_point_path = g_filename_from_uri(mount_point_uri, NULL, &error);
+	if (error) {
+		g_warning("%s", error->message);
+		g_error_free(error);
+		goto error;
+	}
+
+	volume = gnome_vfs_volume_monitor_get_volume_for_path(monitor, mount_point_path);
+	if (volume  == NULL) {
+ 		goto error;
+	}
+	g_free(mount_point_path);
+	g_free(mount_point_uri);
+
+	fstype = gnome_vfs_volume_get_filesystem_type(volume);
+	
+	gnome_vfs_volume_unref(volume);
+	
+	return fstype;
+
+ error:
+	if (volume != NULL) {
+		gnome_vfs_volume_unref(volume);
+	}
+	g_free(mount_point_path);
+	g_free(mount_point_uri);
+	return NULL;
+}
+
 gboolean
 rb_uri_is_mounted (const char *uri)
 {

Modified: trunk/lib/rb-util.h
==============================================================================
--- trunk/lib/rb-util.h	(original)
+++ trunk/lib/rb-util.h	Sun Jun 15 12:30:48 2008
@@ -55,6 +55,8 @@
 GtkWidget *rb_image_new_from_stock (const gchar *stock_id, GtkIconSize size);
 
 gchar *rb_uri_get_mount_point (const char *uri);
+gchar *rb_uri_get_filesystem_type(const char *uri);
+
 gboolean rb_uri_is_mounted (const char *uri);
 
 

Modified: trunk/sources/rb-removable-media-source.c
==============================================================================
--- trunk/sources/rb-removable-media-source.c	(original)
+++ trunk/sources/rb-removable-media-source.c	Sun Jun 15 12:30:48 2008
@@ -517,7 +517,8 @@
 					  const char *extension)
 {
 	RBRemovableMediaSourceClass *klass = RB_REMOVABLE_MEDIA_SOURCE_GET_CLASS (source);
-	char *uri;
+	char *uri = NULL;
+	char *sane_uri = NULL;
 
 	if (klass->impl_build_dest_uri) {
 		uri = klass->impl_build_dest_uri (source, entry, mimetype, extension);
@@ -525,6 +526,11 @@
 		uri = NULL;
 	}
 
+	sane_uri = rb_sanitize_uri_for_filesystem(uri);
+	g_return_val_if_fail(sane_uri != NULL, NULL);
+	g_free(uri);
+	uri = sane_uri;
+
 	rb_debug ("Built dest URI for mime='%s', extension='%s': '%s'",
 		  mimetype,
 		  extension,



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