[rhythmbox] file-helpers: skip the mount point when sanitizing a URI



commit f1862aa20a233d39ebe879b196be57492c56c5a3
Author: Jonathan Matthew <jonathan d14n org>
Date:   Thu Apr 15 22:52:03 2010 +1000

    file-helpers: skip the mount point when sanitizing a URI
    
    This is important when the mount point is not valid for the filesystem
    type that it contains.

 lib/rb-file-helpers.c |   53 +++++++++++++++++++++++++++++++++++++++++++++---
 lib/rb-file-helpers.h |    2 +-
 2 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/lib/rb-file-helpers.c b/lib/rb-file-helpers.c
index cc62652..5a0f96d 100644
--- a/lib/rb-file-helpers.c
+++ b/lib/rb-file-helpers.c
@@ -1403,13 +1403,14 @@ rb_file_find_extant_parent (GFile *file)
 /**
  * rb_uri_get_filesystem_type:
  * @uri: URI to get filesystem type for
+ * @mount_point: optionally returns the mount point for the filesystem as a URI
  *
  * Returns a string describing the type of the filesystem containing @uri.
  *
  * Return value: filesystem type string, must be freed by caller.
  */
 char *
-rb_uri_get_filesystem_type (const char *uri)
+rb_uri_get_filesystem_type (const char *uri, char **mount_point)
 {
 	GFile *file;
 	GFile *extant;
@@ -1417,6 +1418,10 @@ rb_uri_get_filesystem_type (const char *uri)
 	char *fstype = NULL;
 	GError *error = NULL;
 
+	if (mount_point != NULL) {
+		*mount_point = NULL;
+	}
+
 	/* ignore our own internal URI schemes */
 	if (g_str_has_prefix (uri, "xrb")) {
 		return NULL;
@@ -1434,6 +1439,13 @@ rb_uri_get_filesystem_type (const char *uri)
 		return NULL;
 	}
 
+	if (mount_point != NULL) {
+		char *extant_uri;
+		extant_uri = g_file_get_uri (extant);
+		*mount_point = rb_uri_get_mount_point (extant_uri);
+		g_free (extant_uri);
+	}
+
 	info = g_file_query_filesystem_info (extant, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, NULL, &error);
 	if (info != NULL) {
 		fstype = g_file_info_get_attribute_as_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
@@ -1474,9 +1486,11 @@ rb_sanitize_path_for_msdos_filesystem (char *path)
 char *
 rb_sanitize_uri_for_filesystem (const char *uri)
 {
-	char *filesystem = rb_uri_get_filesystem_type (uri);
+	char *mountpoint = NULL;
+	char *filesystem;
 	char *sane_uri = NULL;
 
+	filesystem = rb_uri_get_filesystem_type (uri, &mountpoint);
 	if (!filesystem)
 		return g_strdup (uri);
 
@@ -1485,19 +1499,48 @@ rb_sanitize_uri_for_filesystem (const char *uri)
 	    !strcmp (filesystem, "msdos")) {
 	    	char *hostname = NULL;
 		GError *error = NULL;
-	    	char *full_path = g_filename_from_uri (uri, &hostname, &error);
+		char *full_path;
+		char *fat_path;
+
+		full_path = g_filename_from_uri (uri, &hostname, &error);
 
 		if (error) {
 			g_error_free (error);
 			g_free (filesystem);
 			g_free (full_path);
+			g_free (mountpoint);
 			return g_strdup (uri);
 		}
 
-		rb_sanitize_path_for_msdos_filesystem (full_path);
+		/* if we got a mount point, don't sanitize it.  the mountpoint must be
+		 * valid for the filesystem that contains it, but it may not be valid for
+		 * the filesystem it contains.  for example, a vfat filesystem mounted
+		 * at "/media/Pl1:".
+		 */
+		fat_path = full_path;
+		if (mountpoint != NULL) {
+			char *mount_path;
+			mount_path = g_filename_from_uri (mountpoint, NULL, &error);
+			if (error) {
+				rb_debug ("can't convert mountpoint %s to a path: %s", mountpoint, error->message);
+				g_error_free (error);
+			} else if (g_str_has_prefix (full_path, mount_path)) {
+				fat_path = full_path + strlen (mount_path);
+			} else {
+				rb_debug ("path %s doesn't begin with mount path %s somehow", full_path, mount_path);
+			}
+
+			g_free (mount_path);
+		} else {
+			rb_debug ("couldn't get mount point for %s", uri);
+		}
+
+		rb_debug ("sanitizing path %s", fat_path);
+		rb_sanitize_path_for_msdos_filesystem (fat_path);
 
 		/* create a new uri from this */
 		sane_uri = g_filename_to_uri (full_path, hostname, &error);
+		rb_debug ("sanitized URI: %s", sane_uri);
 
 		g_free (hostname);
 		g_free (full_path);
@@ -1505,6 +1548,7 @@ rb_sanitize_uri_for_filesystem (const char *uri)
 		if (error) {
 			g_error_free (error);
 			g_free (filesystem);
+			g_free (mountpoint);
 			return g_strdup (uri);
 		}
 	}
@@ -1512,6 +1556,7 @@ rb_sanitize_uri_for_filesystem (const char *uri)
 	/* add workarounds for other filesystems limitations here */
 
 	g_free (filesystem);
+	g_free (mountpoint);
 	return sane_uri ? sane_uri : g_strdup (uri);
 }
 
diff --git a/lib/rb-file-helpers.h b/lib/rb-file-helpers.h
index 914bbb3..75a0bac 100644
--- a/lib/rb-file-helpers.h
+++ b/lib/rb-file-helpers.h
@@ -92,7 +92,7 @@ gboolean	rb_uri_create_parent_dirs (const char *uri, GError **error);
 void		rb_file_helpers_init	(gboolean uninstalled);
 void		rb_file_helpers_shutdown(void);
 
-char *		rb_uri_get_filesystem_type (const char *uri);
+char *		rb_uri_get_filesystem_type (const char *uri, char **mount_point);
 void		rb_sanitize_path_for_msdos_filesystem (char *path);
 char *		rb_sanitize_uri_for_filesystem(const char *uri);
 



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