Ticket #3973: 0001-Remove-temporary-downloaded-cancelled-files-SL-3973.patch

File 0001-Remove-temporary-downloaded-cancelled-files-SL-3973.patch, 2.5 KB (added by humitos, 12 years ago)
  • webactivity.py

    From 5335d7e1e35e6fa83a55a094c30fce688bb637fc Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Mon, 1 Oct 2012 16:07:41 -0300
    Subject: [PATCH Browse] Remove temporary downloaded (cancelled) files SL
     #3973
    
    When a download is cancelled for any reason WebKit leaves a temporary
    file called ".goutputstream-*" in the "instance" directory. This is
    because of a bug in GLib:
    
     * https://bugzilla.gnome.org/show_bug.cgi?id=629301
    
    This patch is a workaround to that behaviour. Every time that Browse
    is started it looks for all the ".goutputstream" files in the
    "instance" directory and checks its mtime. If it greater than 1 day it
    removes the old temporary file.
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     webactivity.py | 29 +++++++++++++++++++++++++++++
     1 file changed, 29 insertions(+)
    
    diff --git a/webactivity.py b/webactivity.py
    index dff3a4a..6ba1099 100644
    a b from gi.repository import GConf 
    3737import locale
    3838import cairo
    3939import StringIO
     40import datetime
    4041from hashlib import sha1
    4142
    4243from sugar3.activity import activity
    class WebActivity(activity.Activity): 
    241242        else:
    242243            _logger.debug('Created activity')
    243244
     245        # README: this is a workaround to remove old temp file
     246        # http://bugs.sugarlabs.org/ticket/3973
     247        self._cleanup_temp_files()
     248
     249    def _cleanup_temp_files(self):
     250        """Removes temporary files generated by Download Manager that
     251        were cancelled by the user or failed for any reason.
     252
     253        There is a bug in GLib that makes this to happen:
     254            https://bugzilla.gnome.org/show_bug.cgi?id=629301
     255        """
     256
     257        temp_path = os.path.join(self.get_activity_root(), 'instance')
     258        for f in os.listdir(temp_path):
     259            if f.startswith('.goutputstream-'):
     260                fpath = os.path.join(temp_path, f)
     261                mdate = datetime.datetime.fromtimestamp(
     262                    os.path.getmtime(fpath))
     263                now = datetime.datetime.now()
     264                delta = now - mdate
     265                if delta.days > 0:
     266                    logging.warning('Removing old temporary file: %s', fpath)
     267                    try:
     268                        os.remove(fpath)
     269                    except OSError:
     270                        logging.error('Temporary file could not be '
     271                                      'removed: %s', fpath)
     272
    244273    def _on_focus_url_entry(self, gobject):
    245274        self._primary_toolbar.entry.grab_focus()
    246275