[gnome-software] Fix installation of external appstream files
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Fix installation of external appstream files
- Date: Wed, 23 Nov 2016 14:15:02 +0000 (UTC)
commit 52c1afd8f5a9adfb85a4f0ceca8d0bec8b39c2c9
Author: Joaquim Rocha <jrocha endlessm com>
Date: Wed Nov 23 14:49:34 2016 +0100
Fix installation of external appstream files
The files were being installed with a random prefix which meant they
were never replaced as every download would have a different name.
src/plugins/gs-plugin-external-appstream.c | 49 +++++++++++++++++----------
1 files changed, 31 insertions(+), 18 deletions(-)
---
diff --git a/src/plugins/gs-plugin-external-appstream.c b/src/plugins/gs-plugin-external-appstream.c
index 5827a98..658ea1a 100644
--- a/src/plugins/gs-plugin-external-appstream.c
+++ b/src/plugins/gs-plugin-external-appstream.c
@@ -161,14 +161,27 @@ gs_plugin_external_appstream_refresh_url (GsPlugin *plugin,
return FALSE;
}
- /* write the download contents into a temporary file that will be
- * copied into the system */
- tmp_file_tmpl = g_strdup_printf ("XXXXXX_%s", file_name);
- tmp_file = g_file_new_tmp (tmp_file_tmpl, &iostream, error);
- if (tmp_file == NULL)
+ /* write the download contents into a file that will be copied into
+ * the system */
+ tmp_file_path = gs_utils_get_cache_filename ("external-appstream",
+ file_name,
+ GS_UTILS_CACHE_FLAG_WRITEABLE,
+ error);
+ if (tmp_file_path == NULL)
return FALSE;
- tmp_file_path = g_file_get_path (tmp_file);
+ tmp_file = g_file_new_for_path (tmp_file_path);
+
+ /* ensure the file doesn't exist */
+ if (g_file_query_exists (tmp_file, cancellable) &&
+ !g_file_delete (tmp_file, cancellable, error))
+ return FALSE;
+
+ iostream = g_file_create_readwrite (tmp_file, G_FILE_CREATE_NONE,
+ cancellable, error);
+
+ if (iostream == NULL)
+ return FALSE;
g_debug ("Downloaded appstream file %s", tmp_file_path);
@@ -182,20 +195,20 @@ gs_plugin_external_appstream_refresh_url (GsPlugin *plugin,
/* close the file */
g_output_stream_close (outstream, cancellable, NULL);
- if (!file_written) {
- /* clean up the temporary file if we could not write */
- g_file_delete (tmp_file, NULL, NULL);
- return FALSE;
- }
-
/* install file systemwide */
- if (!gs_plugin_external_appstream_install (tmp_file_path,
- cancellable,
- error))
- return FALSE;
- g_debug ("Installed appstream file %s", tmp_file_path);
+ if (file_written) {
+ if (gs_plugin_external_appstream_install (tmp_file_path,
+ cancellable,
+ error)) {
+ g_debug ("Installed appstream file %s", tmp_file_path);
+ } else {
+ file_written = FALSE;
+ }
+ }
- return TRUE;
+ /* clean up the temporary file */
+ g_file_delete (tmp_file, cancellable, NULL);
+ return file_written;
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]