[rhythmbox] file-helpers: improve msdos sanitization a bit



commit 9df306f32644cd67034fe6359014ef93f4006d03
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue Aug 25 08:00:17 2015 +1000

    file-helpers: improve msdos sanitization a bit
    
    Everywhere rb_sanitize_path_for_msdos_filesystem is used, except for
    rb_sanitize_uri_for_filesystem, it's used on individual components
    of a path rather than the whole thing, so it makes sense for it to
    also replace '/' with '-'.  rb_sanitize_uri_for_filesystem now calls
    a different function with the old behaviour.

 lib/rb-file-helpers.c             |   19 ++++++++++++++-----
 plugins/mtpdevice/rb-mtp-source.c |   13 +++----------
 2 files changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/lib/rb-file-helpers.c b/lib/rb-file-helpers.c
index bb9924f..f5454ee 100644
--- a/lib/rb-file-helpers.c
+++ b/lib/rb-file-helpers.c
@@ -1514,18 +1514,27 @@ rb_uri_get_filesystem_type (const char *uri, char **mount_point)
        return fstype;
 }
 
+static void
+sanitize_msdos_path (char *path)
+{
+       g_strdelimit (path, "\"", '\'');
+       g_strdelimit (path, ":|<>*?\\", '_');
+}
+
 /**
  * rb_sanitize_path_for_msdos_filesystem:
- * @path: a path to sanitize (modified in place)
+ * @path: a path segment to sanitize (modified in place)
  *
  * Modifies @path such that it represents a legal path for MS DOS
- * filesystems.
+ * filesystems.  Note that it replaces forward slash characters,
+ * so it's only appropriate for use with individual path segments
+ * rather than entire paths.
  */
 void
 rb_sanitize_path_for_msdos_filesystem (char *path)
 {
-       g_strdelimit (path, "\"", '\'');
-       g_strdelimit (path, ":|<>*?\\", '_');
+       sanitize_msdos_path (path);
+       g_strdelimit (path, "/", '-');
 }
 
 /**
@@ -1596,7 +1605,7 @@ rb_sanitize_uri_for_filesystem (const char *uri, const char *filesystem)
                }
 
                rb_debug ("sanitizing path %s", fat_path);
-               rb_sanitize_path_for_msdos_filesystem (fat_path);
+               sanitize_msdos_path (fat_path);
 
                /* create a new uri from this */
                sane_uri = g_filename_to_uri (full_path, hostname, &error);
diff --git a/plugins/mtpdevice/rb-mtp-source.c b/plugins/mtpdevice/rb-mtp-source.c
index 2e5b3bf..4640dfe 100644
--- a/plugins/mtpdevice/rb-mtp-source.c
+++ b/plugins/mtpdevice/rb-mtp-source.c
@@ -1186,13 +1186,6 @@ impl_track_add_error (RBTransferTarget *target,
 }
 
 static void
-sanitize_for_mtp (char *str)
-{
-       rb_sanitize_path_for_msdos_filesystem (str);
-       g_strdelimit (str, "/", '_');
-}
-
-static void
 prepare_encoder_sink_cb (RBEncoderFactory *factory,
                         const char *stream_uri,
                         GObject *sink,
@@ -1263,9 +1256,9 @@ prepare_encoder_sink_cb (RBEncoderFactory *factory,
        folder_path[1] = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_ALBUM);
 
        /* ensure the filename is safe for FAT filesystems and doesn't contain slashes */
-       sanitize_for_mtp (track->filename);
-       sanitize_for_mtp (folder_path[0]);
-       sanitize_for_mtp (folder_path[1]);
+       rb_sanitize_path_for_msdos_filesystem (track->filename);
+       rb_sanitize_path_for_msdos_filesystem (folder_path[0]);
+       rb_sanitize_path_for_msdos_filesystem (folder_path[1]);
 
        if (rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DATE) > 0) {
                g_date_set_julian (&d, rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DATE));


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