From 70d5b0d0c770d03e07ddd4479ead2a773f24c79e Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Tue, 9 Oct 2012 08:57:06 -0300
Subject: [PATCH v3 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..b784476 100644
a
|
b
|
class WebActivity(activity.Activity): |
241 | 241 | else: |
242 | 242 | _logger.debug('Created activity') |
243 | 243 | |
| 244 | # README: this is a workaround to remove old temp file |
| 245 | # http://bugs.sugarlabs.org/ticket/3973 |
| 246 | self._cleanup_temp_files() |
| 247 | |
| 248 | def _cleanup_temp_files(self): |
| 249 | """Removes temporary files generated by Download Manager that |
| 250 | were cancelled by the user or failed for any reason. |
| 251 | |
| 252 | There is a bug in GLib that makes this to happen: |
| 253 | https://bugzilla.gnome.org/show_bug.cgi?id=629301 |
| 254 | """ |
| 255 | |
| 256 | try: |
| 257 | uptime_proc = open('/proc/uptime', 'r').read() |
| 258 | uptime = int(float(uptime_proc.split()[0])) |
| 259 | except EnvironmentError: |
| 260 | logging.warning('/proc/uptime could not be read') |
| 261 | uptime = None |
| 262 | |
| 263 | temp_path = os.path.join(self.get_activity_root(), 'instance') |
| 264 | now = int(time.time()) |
| 265 | cutoff = now - 24 * 60 * 60 # yesterday |
| 266 | if uptime is not None: |
| 267 | boot_time = now - uptime |
| 268 | cutoff = max(cutoff, boot_time) |
| 269 | |
| 270 | for f in os.listdir(temp_path): |
| 271 | if f.startswith('.goutputstream-'): |
| 272 | fpath = os.path.join(temp_path, f) |
| 273 | mtime = int(os.path.getmtime(fpath)) |
| 274 | if mtime < cutoff: |
| 275 | logging.warning('Removing old temporary file: %s', fpath) |
| 276 | try: |
| 277 | os.remove(fpath) |
| 278 | except EnvironmentError: |
| 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 | |