[gnome-software] external-appstream: Fix use of different file name between check and installation
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] external-appstream: Fix use of different file name between check and installation
- Date: Thu, 11 Jan 2018 10:43:08 +0000 (UTC)
commit bd9ae411da01354e475f545287c9738cc5b88506
Author: Joaquim Rocha <jrocha endlessm com>
Date: Mon Jan 8 12:13:41 2018 +0100
external-appstream: Fix use of different file name between check and installation
The file name used for checking if the appstream file needed to be
refreshed had not been updated to include the org.gnome.Software-
prefix. Thus it was checking a file different from what gets updated
in the end.
These changes refactor a bit how the file is checked and generated,
using a common function to ensure this doesn't happen again.
.../gs-external-appstream-utils.c | 40 ++++++++++++++++++++
.../gs-external-appstream-utils.h | 33 ++++++++++++++++
plugins/external-appstream/gs-install-appstream.c | 18 +++------
.../gs-plugin-external-appstream.c | 10 ++--
plugins/external-appstream/meson.build | 10 ++++-
5 files changed, 92 insertions(+), 19 deletions(-)
---
diff --git a/plugins/external-appstream/gs-external-appstream-utils.c
b/plugins/external-appstream/gs-external-appstream-utils.c
new file mode 100644
index 0000000..ff68143
--- /dev/null
+++ b/plugins/external-appstream/gs-external-appstream-utils.c
@@ -0,0 +1,40 @@
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2018 Endless Mobile, Inc.
+ *
+ * Authors: Joaquim Rocha <jrocha endlessm com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "gs-external-appstream-utils.h"
+
+#define APPSTREAM_SYSTEM_DIR LOCALSTATEDIR "/cache/app-info/xmls"
+
+gchar *
+gs_external_appstream_utils_get_file_cache_path (const gchar *file_name)
+{
+ g_autofree gchar *prefixed_file_name = g_strdup_printf ("org.gnome.Software-%s",
+ file_name);
+ return g_build_filename (APPSTREAM_SYSTEM_DIR, prefixed_file_name, NULL);
+}
+
+const gchar *
+gs_external_appstream_utils_get_system_dir (void)
+{
+ return APPSTREAM_SYSTEM_DIR;
+}
diff --git a/plugins/external-appstream/gs-external-appstream-utils.h
b/plugins/external-appstream/gs-external-appstream-utils.h
new file mode 100644
index 0000000..d1e0f25
--- /dev/null
+++ b/plugins/external-appstream/gs-external-appstream-utils.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2018 Endless Mobile, Inc.
+ *
+ * Authors: Joaquim Rocha <jrocha endlessm com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GS_EXTERNAL_APPSTREAM_UTILS_H
+#define GS_EXTERNAL_APPSTREAM_UTILS_H
+
+#include <config.h>
+#include <glib.h>
+
+const gchar *gs_external_appstream_utils_get_system_dir (void);
+gchar *gs_external_appstream_utils_get_file_cache_path (const gchar *file_name);
+
+#endif /* GS_EXTERNAL_APPSTREAM_UTILS_H */
diff --git a/plugins/external-appstream/gs-install-appstream.c
b/plugins/external-appstream/gs-install-appstream.c
index fb697da..d4a430c 100644
--- a/plugins/external-appstream/gs-install-appstream.c
+++ b/plugins/external-appstream/gs-install-appstream.c
@@ -29,20 +29,18 @@
#include <glib/gi18n.h>
#include <glib-object.h>
+#include "gs-external-appstream-utils.h"
+
static gboolean
gs_install_appstream_copy_file (GFile *file, GError **error)
{
- g_autofree gchar *basename = NULL;
- g_autofree gchar *basename_prefixed = NULL;
- g_autofree gchar *cachedir = NULL;
- g_autofree gchar *cachefn = NULL;
- g_autoptr(GFile) cachedir_file = NULL;
- g_autoptr(GFile) cachefn_file = NULL;
+ g_autofree gchar *basename = g_file_get_basename (file);
+ g_autofree gchar *cachefn = gs_external_appstream_utils_get_file_cache_path (basename);
+ g_autoptr(GFile) cachefn_file = g_file_new_for_path (cachefn);
+ g_autoptr(GFile) cachedir_file = g_file_get_parent (cachefn_file);
/* make sure the parent directory exists, but if not then create with
* the ownership and permissions of the current process */
- cachedir = g_build_filename (LOCALSTATEDIR, "cache", "app-info", "xmls", NULL);
- cachedir_file = g_file_new_for_path (cachedir);
if (!g_file_query_exists (cachedir_file, NULL)) {
if (!g_file_make_directory_with_parents (cachedir_file, NULL, error))
return FALSE;
@@ -50,10 +48,6 @@ gs_install_appstream_copy_file (GFile *file, GError **error)
/* do the copy, overwriting existing files and setting the permissions
* of the current process (so that should be -rw-r--r--) */
- basename = g_file_get_basename (file);
- basename_prefixed = g_strdup_printf ("org.gnome.Software-%s", basename);
- cachefn = g_build_filename (cachedir, basename_prefixed, NULL);
- cachefn_file = g_file_new_for_path (cachefn);
return g_file_copy (file, cachefn_file,
G_FILE_COPY_OVERWRITE |
G_FILE_COPY_NOFOLLOW_SYMLINKS |
diff --git a/plugins/external-appstream/gs-plugin-external-appstream.c
b/plugins/external-appstream/gs-plugin-external-appstream.c
index 672f15b..80b7af0 100644
--- a/plugins/external-appstream/gs-plugin-external-appstream.c
+++ b/plugins/external-appstream/gs-plugin-external-appstream.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2016 Endless Mobile, Inc.
+ * Copyright (C) 2016-2018 Endless Mobile, Inc.
*
* Authors: Joaquim Rocha <jrocha endlessm com>
*
@@ -24,8 +24,7 @@
#include <config.h>
#include <gnome-software.h>
-
-#define APPSTREAM_SYSTEM_DIR LOCALSTATEDIR "/cache/app-info/xmls"
+#include "gs-external-appstream-utils.h"
struct GsPluginData {
GSettings *settings;
@@ -35,13 +34,14 @@ void
gs_plugin_initialize (GsPlugin *plugin)
{
GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ const gchar *system_dir = gs_external_appstream_utils_get_system_dir ();
priv->settings = g_settings_new ("org.gnome.software");
/* run it before the appstream plugin */
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream");
- g_debug ("appstream system dir: %s", APPSTREAM_SYSTEM_DIR);
+ g_debug ("appstream system dir: %s", system_dir);
}
void
@@ -122,7 +122,7 @@ gs_plugin_external_appstream_refresh_url (GsPlugin *plugin,
/* check age */
file_name = g_path_get_basename (url);
- target_file_path = g_build_filename (APPSTREAM_SYSTEM_DIR, file_name, NULL);
+ target_file_path = gs_external_appstream_utils_get_file_cache_path (file_name);
if (!gs_plugin_external_appstream_check (target_file_path, cache_age)) {
g_debug ("skipping updating external appstream file %s: "
"cache age is older than file",
diff --git a/plugins/external-appstream/meson.build b/plugins/external-appstream/meson.build
index ea5d3d2..6e2f3df 100644
--- a/plugins/external-appstream/meson.build
+++ b/plugins/external-appstream/meson.build
@@ -2,7 +2,10 @@ cargs = ['-DG_LOG_DOMAIN="GsPluginExternalAppstream"']
executable(
'gnome-software-install-appstream',
- sources : 'gs-install-appstream.c',
+ sources : [
+ 'gs-external-appstream-utils.c',
+ 'gs-install-appstream.c',
+ ],
include_directories : [
include_directories('../..'),
],
@@ -14,7 +17,10 @@ executable(
shared_module(
'gs_plugin_external-appstream',
-sources : 'gs-plugin-external-appstream.c',
+ sources : [
+ 'gs-external-appstream-utils.c',
+ 'gs-plugin-external-appstream.c',
+ ],
include_directories : [
include_directories('../..'),
include_directories('../../lib'),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]