[gnome-software/gnome-3-26] Copy files installed from /tmp
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-26] Copy files installed from /tmp
- Date: Sun, 17 Dec 2017 08:52:42 +0000 (UTC)
commit e2ba495e5c187a9b3c187182ad6d6ad9011892f6
Author: Richard Hughes <richard hughsie com>
Date: Tue Dec 5 12:52:49 2017 +0000
Copy files installed from /tmp
When downloading a file with a file that is auto-opened in gnome-software, some
web browsers like Firefox download the file to /tmp rather than ~/Downloads.
This prompts the user to confirm the installation in gnome-software before it is
actually deployed onto the system. If Firefox is then closed it deletes all the
content in /tmp/mozilla, and clicking 'Install' in gnome-software leads to an
error saying the file can no longer be read.
To fix this, copy files in /tmp to the ~/.cache/gnome-software/downloads
directory. We could have used a hardlink into the /tmp/mozilla folder, but if
the directory is deleted or if the mount no longer exists (e.g. for flatpak)
then this isn't going to work.
Given even 'large' RPMs are only a few Mb, copying sees the pragmatic choice.
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=784990
src/gs-application.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 44 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 264443e..e55cf79 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -625,6 +625,35 @@ install_activated (GSimpleAction *action,
gs_shell_install (app->shell, a, interaction);
}
+static GFile *
+_copy_file_to_cache (GFile *file_src, GError **error)
+{
+ g_autoptr(GFile) file_dest = NULL;
+ g_autofree gchar *cache_dir = NULL;
+ g_autofree gchar *cache_fn = NULL;
+ g_autofree gchar *filename = NULL;
+ g_autofree gchar *basename = NULL;
+
+ /* get destination location */
+ filename = g_file_get_path (file_src);
+ cache_dir = g_dir_make_tmp ("gnome-software-XXXXXX", error);
+ if (cache_dir == NULL)
+ return NULL;
+ basename = g_file_get_basename (file_src);
+ cache_fn = g_build_filename (cache_dir, basename, NULL);
+
+ /* copy file to cache */
+ file_dest = g_file_new_for_path (cache_fn);
+ if (!g_file_copy (file_src, file_dest,
+ G_FILE_COPY_OVERWRITE,
+ NULL, /* cancellable */
+ NULL, NULL, /* progress */
+ error)) {
+ return NULL;
+ }
+ return g_steal_pointer (&file_dest);
+}
+
static void
filename_activated (GSimpleAction *action,
GVariant *parameter,
@@ -637,7 +666,21 @@ filename_activated (GSimpleAction *action,
gs_application_initialize_ui (app);
g_variant_get (parameter, "(&s)", &filename);
- file = g_file_new_for_path (filename);
+
+ /* this could go away at any moment, so make a local copy */
+ if (g_str_has_prefix (filename, "/tmp") ||
+ g_str_has_prefix (filename, "/var/tmp")) {
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GFile) file_src = g_file_new_for_path (filename);
+ file = _copy_file_to_cache (file_src, &error);
+ if (file == NULL) {
+ g_warning ("failed to copy file, falling back to %s: %s",
+ filename, error->message);
+ file = g_file_new_for_path (filename);
+ }
+ } else {
+ file = g_file_new_for_path (filename);
+ }
gs_shell_show_local_file (app->shell, file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]