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 |
37 | 37 | import locale |
38 | 38 | import cairo |
39 | 39 | import StringIO |
| 40 | import datetime |
40 | 41 | from hashlib import sha1 |
41 | 42 | |
42 | 43 | from sugar3.activity import activity |
… |
… |
class WebActivity(activity.Activity): |
241 | 242 | else: |
242 | 243 | _logger.debug('Created activity') |
243 | 244 | |
| 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 | |
244 | 273 | def _on_focus_url_entry(self, gobject): |
245 | 274 | self._primary_toolbar.entry.grab_focus() |
246 | 275 | |