Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webactivity.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-10-09 11:57:06 (GMT)
committer Manuel Quiñones <manuq@laptop.org>2012-11-16 18:15:51 (GMT)
commit32764d06d373c8fba9e87044e86e30b291730f16 (patch)
tree680d81b8890d6c9e01646d6eb67079aeba89b988 /webactivity.py
parentf96848a9fb4537e01994c096659541a967dd749f (diff)
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> Acked-by: Manuel Quiñones <manuq@laptop.org>
Diffstat (limited to 'webactivity.py')
-rw-r--r--webactivity.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/webactivity.py b/webactivity.py
index d140128..6dbd222 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -241,6 +241,44 @@ class WebActivity(activity.Activity):
else:
_logger.debug('Created activity')
+ # README: this is a workaround to remove old temp file
+ # http://bugs.sugarlabs.org/ticket/3973
+ self._cleanup_temp_files()
+
+ def _cleanup_temp_files(self):
+ """Removes temporary files generated by Download Manager that
+ were cancelled by the user or failed for any reason.
+
+ There is a bug in GLib that makes this to happen:
+ https://bugzilla.gnome.org/show_bug.cgi?id=629301
+ """
+
+ try:
+ uptime_proc = open('/proc/uptime', 'r').read()
+ uptime = int(float(uptime_proc.split()[0]))
+ except EnvironmentError:
+ logging.warning('/proc/uptime could not be read')
+ uptime = None
+
+ temp_path = os.path.join(self.get_activity_root(), 'instance')
+ now = int(time.time())
+ cutoff = now - 24 * 60 * 60 # yesterday
+ if uptime is not None:
+ boot_time = now - uptime
+ cutoff = max(cutoff, boot_time)
+
+ for f in os.listdir(temp_path):
+ if f.startswith('.goutputstream-'):
+ fpath = os.path.join(temp_path, f)
+ mtime = int(os.path.getmtime(fpath))
+ if mtime < cutoff:
+ logging.warning('Removing old temporary file: %s', fpath)
+ try:
+ os.remove(fpath)
+ except EnvironmentError:
+ logging.error('Temporary file could not be '
+ 'removed: %s', fpath)
+
def _on_focus_url_entry(self, gobject):
self._primary_toolbar.entry.grab_focus()