[rhythmbox] lib: optionally pass in a filesystem type to sanitize for



commit 1cc68e1decffe3abe1398eeab27fef18802f3fc7
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat Mar 8 12:05:09 2014 +1000

    lib: optionally pass in a filesystem type to sanitize for
    
    In some situations (mostly fuse) we can't determine the type of
    filesystem we're writing to, so the best we can do is guess based
    on filenames it rejects.

 lib/rb-file-helpers.c        |   25 +++++++++++++++----------
 lib/rb-file-helpers.h        |    2 +-
 podcast/rb-podcast-manager.c |    2 +-
 sources/rb-library-source.c  |    2 +-
 sources/rb-transfer-target.c |    2 +-
 5 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/lib/rb-file-helpers.c b/lib/rb-file-helpers.c
index a309cc3..b1c906d 100644
--- a/lib/rb-file-helpers.c
+++ b/lib/rb-file-helpers.c
@@ -1497,23 +1497,28 @@ rb_sanitize_path_for_msdos_filesystem (char *path)
 /**
  * rb_sanitize_uri_for_filesystem:
  * @uri: a URI to sanitize
+ * @filesystem: (allow none): a specific filesystem to sanitize for
  *
  * Removes characters from @uri that are not allowed by the filesystem
- * on which it would be stored.  At present, this only supports MS DOS
- * filesystems.
+ * on which it would be stored, or a specific type of filesystem if specified.
+ * At present, this only supports MS DOS filesystems.
  *
  * Return value: sanitized copy of @uri, must be freed by caller.
  */
 char *
-rb_sanitize_uri_for_filesystem (const char *uri)
+rb_sanitize_uri_for_filesystem (const char *uri, const char *filesystem)
 {
+       char *free_fs = NULL;
        char *mountpoint = NULL;
-       char *filesystem;
        char *sane_uri = NULL;
 
-       filesystem = rb_uri_get_filesystem_type (uri, &mountpoint);
-       if (!filesystem)
-               return g_strdup (uri);
+       if (filesystem == NULL) {
+               free_fs = rb_uri_get_filesystem_type (uri, &mountpoint);
+               if (!free_fs)
+                       return g_strdup (uri);
+
+               filesystem = free_fs;
+       }
 
        if (!strcmp (filesystem, "fat") ||
            !strcmp (filesystem, "vfat") ||
@@ -1527,7 +1532,7 @@ rb_sanitize_uri_for_filesystem (const char *uri)
 
                if (error) {
                        g_error_free (error);
-                       g_free (filesystem);
+                       g_free (free_fs);
                        g_free (full_path);
                        g_free (mountpoint);
                        return g_strdup (uri);
@@ -1568,7 +1573,7 @@ rb_sanitize_uri_for_filesystem (const char *uri)
 
                if (error) {
                        g_error_free (error);
-                       g_free (filesystem);
+                       g_free (free_fs);
                        g_free (mountpoint);
                        return g_strdup (uri);
                }
@@ -1576,7 +1581,7 @@ rb_sanitize_uri_for_filesystem (const char *uri)
 
        /* add workarounds for other filesystems limitations here */
 
-       g_free (filesystem);
+       g_free (free_fs);
        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 99748ae..96ce50a 100644
--- a/lib/rb-file-helpers.h
+++ b/lib/rb-file-helpers.h
@@ -94,7 +94,7 @@ void          rb_file_helpers_shutdown(void);
 
 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);
+char *         rb_sanitize_uri_for_filesystem(const char *uri, const char *filesystem);
 
 G_END_DECLS
 
diff --git a/podcast/rb-podcast-manager.c b/podcast/rb-podcast-manager.c
index ef2f415..cda749a 100644
--- a/podcast/rb-podcast-manager.c
+++ b/podcast/rb-podcast-manager.c
@@ -885,7 +885,7 @@ download_podcast (GFileInfo *src_info, RBPodcastManagerInfo *data)
        g_free (feed_folder);
        g_free (esc_local_file_name);
 
-       sane_local_file_uri = rb_sanitize_uri_for_filesystem (local_file_uri);
+       sane_local_file_uri = rb_sanitize_uri_for_filesystem (local_file_uri, NULL);
        g_free (local_file_uri);
 
        rb_debug ("download URI: %s", sane_local_file_uri);
diff --git a/sources/rb-library-source.c b/sources/rb-library-source.c
index 87233b0..835b953 100644
--- a/sources/rb-library-source.c
+++ b/sources/rb-library-source.c
@@ -1631,7 +1631,7 @@ get_dest_uri_cb (RBTrackTransferBatch *batch,
                return NULL;
        }
 
-       sane_dest = rb_sanitize_uri_for_filesystem (dest);
+       sane_dest = rb_sanitize_uri_for_filesystem (dest, NULL);
        g_free (dest);
        rb_debug ("destination URI for %s is %s",
                  rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION),
diff --git a/sources/rb-transfer-target.c b/sources/rb-transfer-target.c
index 1056a05..4f37837 100644
--- a/sources/rb-transfer-target.c
+++ b/sources/rb-transfer-target.c
@@ -92,7 +92,7 @@ rb_transfer_target_build_dest_uri (RBTransferTarget *target,
        if (uri != NULL) {
                char *sane_uri;
 
-               sane_uri = rb_sanitize_uri_for_filesystem (uri);
+               sane_uri = rb_sanitize_uri_for_filesystem (uri, NULL);
                g_return_val_if_fail (sane_uri != NULL, NULL);
                g_free (uri);
                uri = sane_uri;


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