[evince] attachments: Save attachments in a temporary directory



commit e6c351314f185b939714fc6d2cced7d3f14bfe65
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Oct 17 16:49:30 2016 +0200

    attachments: Save attachments in a temporary directory
    
    In order to present the file name "as is", it makes evince store
    its temporary attachment inside a `evince.XXXXXX` subdirectory
    instead of the previous approach of concatenating XXXXXX to the
    file name, which overrided the extension.
    
    From the user's point of view, when opening the attachment, the
    filename will have the same as displayed in Evince, which is
    what the user likely expects.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772188
    
    Fixes #711

 libdocument/ev-attachment.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/libdocument/ev-attachment.c b/libdocument/ev-attachment.c
index fa9a1c28..4710d778 100644
--- a/libdocument/ev-attachment.c
+++ b/libdocument/ev-attachment.c
@@ -422,14 +422,21 @@ ev_attachment_open (EvAttachment *attachment,
                                                   timestamp, error);
        } else {
                 char *basename;
-                char *template;
+                char *temp_dir;
+                char *file_path;
                GFile *file;
 
-                /* FIXMEchpe: convert to filename encoding first! */
+                /* FIXMEchpe: convert to filename encoding first!
+                 * Store the file inside a temporary XXXXXX subdirectory to
+                 * keep the filename "as is".
+                 */
                 basename = g_path_get_basename (ev_attachment_get_name (attachment));
-                template = g_strdup_printf ("%s.XXXXXX", basename);
-                file = ev_mkstemp_file (template, error);
-                g_free (template);
+                temp_dir = g_dir_make_tmp ("evince.XXXXXX", error);
+                file_path = g_build_filename (temp_dir, basename, NULL);
+                file = g_file_new_for_path (file_path);
+
+                g_free (temp_dir);
+                g_free (file_path);
                 g_free (basename);
 
                if (file != NULL && ev_attachment_save (attachment, file, error)) {


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