Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--dnd.py1
-rw-r--r--filepicker.py22
-rwxr-xr-xwebtoolbar.py2
4 files changed, 27 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 821628b..97bfbfd 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
+* #2364: Fix uploads and clean up correctly the temp files. (tomeu)
+
33
-* #2196: Improve the download of big documents to the clipboard.
+* #2196: Improve the download of big documents to the clipboard. (tomeu)
32
diff --git a/dnd.py b/dnd.py
index 9f94a02..d587b6b 100644
--- a/dnd.py
+++ b/dnd.py
@@ -16,6 +16,7 @@
import os
import tempfile
+import logging
from xpcom.nsError import *
from xpcom import ServerException
diff --git a/filepicker.py b/filepicker.py
index 61e0abd..5b24c7c 100644
--- a/filepicker.py
+++ b/filepicker.py
@@ -15,6 +15,9 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
+import os
+import tempfile
+import shutil
import gtk
@@ -25,6 +28,13 @@ from xpcom.server.factory import Factory
from sugar.graphics.objectchooser import ObjectChooser
+_temp_files_to_clean = []
+
+def cleanup_temp_files():
+ for temp_file in _temp_files_to_clean:
+ logging.debug('filepicker.cleanup_temp_files: %r' % temp_file)
+ os.remove(temp_file)
+
class FilePicker:
_com_interfaces_ = interfaces.nsIFilePicker
@@ -62,9 +72,18 @@ class FilePicker:
try:
result = chooser.run()
if result == gtk.RESPONSE_ACCEPT:
+ logging.debug('FilePicker.show: %r' % chooser.get_selected_object())
jobject = chooser.get_selected_object()
if jobject and jobject.file_path:
- self._file = jobject.file_path
+ ext = os.path.splitext(jobject.file_path)[1]
+ f, new_temp = tempfile.mkstemp(ext)
+ del f
+
+ global _temp_files_to_clean
+ _temp_files_to_clean.append(new_temp)
+ shutil.copy(jobject.file_path, new_temp)
+
+ self._file = new_temp
finally:
chooser.destroy()
del chooser
@@ -103,6 +122,7 @@ class FilePicker:
return None
def get_file(self):
+ logging.debug('FilePicker.get_file: %r' % self._file)
if self._file:
cls = components.classes["@mozilla.org/file/local;1"]
local_file = cls.createInstance(interfaces.nsILocalFile)
diff --git a/webtoolbar.py b/webtoolbar.py
index 3a0b61b..56ccc86 100755
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -29,6 +29,7 @@ from sugar.graphics import AddressEntry
import sessionhistory
import progresslistener
+import filepicker
class WebToolbar(gtk.Toolbar):
def __init__(self, browser):
@@ -84,6 +85,7 @@ class WebToolbar(gtk.Toolbar):
def _location_changed_cb(self, progress_listener, uri):
self._set_address(uri)
self._update_navigation_buttons()
+ filepicker.cleanup_temp_files()
def _loading_start_cb(self, progress_listener):
self._set_title(None)