[Sugar-devel] [PATCH Browse] Remove temporary downloaded (cancelled) files SL #3973
Manuel Kaufmann
humitos at gmail.com
Mon Oct 1 15:14:51 EDT 2012
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 at gmail.com>
---
webactivity.py | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/webactivity.py b/webactivity.py
index dff3a4a..6ba1099 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -37,6 +37,7 @@ from gi.repository import GConf
import locale
import cairo
import StringIO
+import datetime
from hashlib import sha1
from sugar3.activity import activity
@@ -241,6 +242,34 @@ 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
+ """
+
+ temp_path = os.path.join(self.get_activity_root(), 'instance')
+ for f in os.listdir(temp_path):
+ if f.startswith('.goutputstream-'):
+ fpath = os.path.join(temp_path, f)
+ mdate = datetime.datetime.fromtimestamp(
+ os.path.getmtime(fpath))
+ now = datetime.datetime.now()
+ delta = now - mdate
+ if delta.days > 0:
+ logging.warning('Removing old temporary file: %s', fpath)
+ try:
+ os.remove(fpath)
+ except OSError:
+ logging.error('Temporary file could not be '
+ 'removed: %s', fpath)
+
def _on_focus_url_entry(self, gobject):
self._primary_toolbar.entry.grab_focus()
--
1.7.11.4
More information about the Sugar-devel
mailing list