[gnome-software] Only replace @datadir@ when we rewrite the CSS resource



commit 78d5c28fd0674d6a94ec884179db870bcf3a40e6
Author: Richard Hughes <richard hughsie com>
Date:   Tue May 16 11:16:33 2017 +0100

    Only replace @datadir@ when we rewrite the CSS resource
    
    These no need to do this for every metadata key.

 lib/gs-app.c    |    7 +------
 lib/gs-plugin.c |    5 +++++
 src/gs-editor.c |    7 +------
 3 files changed, 7 insertions(+), 12 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index f4549bd..aee3432 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -2753,7 +2753,6 @@ gs_app_set_metadata (GsApp *app, const gchar *key, const gchar *value)
 {
        g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&app->mutex);
        const gchar *found;
-       GString *str;
 
        g_return_if_fail (GS_IS_APP (app));
 
@@ -2772,11 +2771,7 @@ gs_app_set_metadata (GsApp *app, const gchar *key, const gchar *value)
                           app->id, key, found, value);
                return;
        }
-       str = g_string_new (value);
-       as_utils_string_replace (str, "@datadir@", DATADIR);
-       g_hash_table_insert (app->metadata,
-                            g_strdup (key),
-                            g_string_free (str, FALSE));
+       g_hash_table_insert (app->metadata, g_strdup (key), g_strdup (value));
 }
 
 /**
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 55e999b..ddb6912 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -1397,12 +1397,17 @@ gs_plugin_download_rewrite_resource (GsPlugin *plugin,
                                     GError **error)
 {
        guint start = 0;
+       g_autoptr(GString) resource_str = g_string_new (resource);
        g_autoptr(GString) str = g_string_new (NULL);
 
        g_return_val_if_fail (GS_IS_PLUGIN (plugin), NULL);
        g_return_val_if_fail (resource != NULL, NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
+       /* replace datadir */
+       as_utils_string_replace (resource_str, "@datadir@", DATADIR);
+       resource = resource_str->str;
+
        /* look in string for any url() links */
        for (guint i = 0; resource[i] != '\0'; i++) {
                if (i > 4 && strncmp (resource + i - 4, "url(", 4) == 0) {
diff --git a/src/gs-editor.c b/src/gs-editor.c
index d8f7f45..bb5e25b 100644
--- a/src/gs-editor.c
+++ b/src/gs-editor.c
@@ -49,13 +49,8 @@ static gchar *
 gs_editor_css_download_resources (GsEditor *self, const gchar *css, GError **error)
 {
        g_autoptr(GsPlugin) plugin = NULL;
-       g_autoptr(GString) css2 = NULL;
        g_autoptr(SoupSession) soup_session = NULL;
 
-       /* replace keywords */
-       css2 = g_string_new (css);
-       as_utils_string_replace (css2, "@datadir@", DATADIR);
-
        /* make remote URIs local */
        plugin = gs_plugin_new ();
        gs_plugin_set_name (plugin, "editor");
@@ -63,7 +58,7 @@ gs_editor_css_download_resources (GsEditor *self, const gchar *css, GError **err
                                                      SOUP_SESSION_TIMEOUT, 10,
                                                      NULL);
        gs_plugin_set_soup_session (plugin, soup_session);
-       return gs_plugin_download_rewrite_resource (plugin, css2->str, NULL, error);
+       return gs_plugin_download_rewrite_resource (plugin, css, NULL, error);
 }
 
 typedef struct {


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