From 436550c4cfbb8637f797a3045d266634c9718b66 Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Mon, 1 Oct 2012 16:07:41 -0300
Subject: [PATCH v2 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 or
it was created before we booted, Browse removes the old temporary
file.
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
---
webactivity.py | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/webactivity.py b/webactivity.py
index dff3a4a..8c66ac5 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 | try: |
| 258 | uptime_proc = open('/proc/uptime', 'r').read() |
| 259 | uptime_seconds = float(uptime_proc.split()[0]) |
| 260 | uptime = datetime.timedelta(seconds=uptime_seconds) |
| 261 | except: |
| 262 | logging.warning('/proc/uptime could not be read') |
| 263 | uptime = None |
| 264 | |
| 265 | temp_path = os.path.join(self.get_activity_root(), 'instance') |
| 266 | now = datetime.datetime.now() |
| 267 | for f in os.listdir(temp_path): |
| 268 | if f.startswith('.goutputstream-'): |
| 269 | fpath = os.path.join(temp_path, f) |
| 270 | mtime = os.path.getmtime(fpath) |
| 271 | mdate = datetime.datetime.fromtimestamp(mtime) |
| 272 | delta = now - mdate |
| 273 | if delta.days > 0 or \ |
| 274 | (uptime is not None and (now - uptime) > mdate): |
| 275 | logging.warning('Removing old temporary file: %s', fpath) |
| 276 | try: |
| 277 | os.remove(fpath) |
| 278 | except OSError: |
| 279 | logging.error('Temporary file could not be ' |
| 280 | 'removed: %s', fpath) |
| 281 | |
244 | 282 | def _on_focus_url_entry(self, gobject): |
245 | 283 | self._primary_toolbar.entry.grab_focus() |
246 | 284 | |