Fix some temp file leaks.
This commit is contained in:
parent
9ce80ca958
commit
cb6d459815
@ -197,8 +197,9 @@ class Shell(gobject.GObject):
|
|||||||
screenshot.get_from_drawable(window, window.get_colormap(), x_orig, y_orig, 0, 0,
|
screenshot.get_from_drawable(window, window.get_colormap(), x_orig, y_orig, 0, 0,
|
||||||
width, height)
|
width, height)
|
||||||
screenshot.save(file_path, "png")
|
screenshot.save(file_path, "png")
|
||||||
|
try:
|
||||||
jobject = datastore.create()
|
jobject = datastore.create()
|
||||||
|
try:
|
||||||
jobject.metadata['title'] = _('Screenshot')
|
jobject.metadata['title'] = _('Screenshot')
|
||||||
jobject.metadata['keep'] = '0'
|
jobject.metadata['keep'] = '0'
|
||||||
jobject.metadata['buddies'] = ''
|
jobject.metadata['buddies'] = ''
|
||||||
@ -207,4 +208,9 @@ class Shell(gobject.GObject):
|
|||||||
jobject.metadata['mime_type'] = 'image/png'
|
jobject.metadata['mime_type'] = 'image/png'
|
||||||
jobject.file_path = file_path
|
jobject.file_path = file_path
|
||||||
datastore.write(jobject)
|
datastore.write(jobject)
|
||||||
|
finally:
|
||||||
|
datastore.destroy()
|
||||||
|
del datastore
|
||||||
|
finally:
|
||||||
|
os.remove(file_path)
|
||||||
|
|
||||||
|
@ -234,6 +234,7 @@ class Activity(Window, gtk.Container):
|
|||||||
self._internal_joined_cb(self._shared_activity, True, None)
|
self._internal_joined_cb(self._shared_activity, True, None)
|
||||||
|
|
||||||
self._bus = ActivityService(self)
|
self._bus = ActivityService(self)
|
||||||
|
self._owns_file = False
|
||||||
|
|
||||||
if handle.object_id:
|
if handle.object_id:
|
||||||
self._jobject = datastore.get(handle.object_id)
|
self._jobject = datastore.get(handle.object_id)
|
||||||
@ -346,8 +347,12 @@ class Activity(Window, gtk.Container):
|
|||||||
else:
|
else:
|
||||||
self.metadata['preview'] = self._preview
|
self.metadata['preview'] = self._preview
|
||||||
try:
|
try:
|
||||||
|
if self._jobject.file_path:
|
||||||
|
self.write_file(self._jobject.file_path)
|
||||||
|
else:
|
||||||
file_path = os.path.join(tempfile.gettempdir(), '%i' % time.time())
|
file_path = os.path.join(tempfile.gettempdir(), '%i' % time.time())
|
||||||
self.write_file(file_path)
|
self.write_file(file_path)
|
||||||
|
self._owns_file = True
|
||||||
self._jobject.file_path = file_path
|
self._jobject.file_path = file_path
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
pass
|
pass
|
||||||
@ -410,6 +415,13 @@ class Activity(Window, gtk.Container):
|
|||||||
self._preview = self._get_preview()
|
self._preview = self._get_preview()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
if self._jobject:
|
||||||
|
if self._owns_file and os.path.isfile(self._jobject.file_path):
|
||||||
|
os.remove(self._jobject.file_path)
|
||||||
|
self._owns_file = False
|
||||||
|
self._jobject.destroy()
|
||||||
|
self._jobject = None
|
||||||
|
|
||||||
def get_metadata(self):
|
def get_metadata(self):
|
||||||
if self._jobject:
|
if self._jobject:
|
||||||
return self._jobject.metadata
|
return self._jobject.metadata
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
@ -62,11 +63,13 @@ class DSMetadata(gobject.GObject):
|
|||||||
def get_dictionary(self):
|
def get_dictionary(self):
|
||||||
return self._props
|
return self._props
|
||||||
|
|
||||||
class DSObject:
|
class DSObject(object):
|
||||||
def __init__(self, object_id, metadata=None, file_path=None):
|
def __init__(self, object_id, metadata=None, file_path=None):
|
||||||
self.object_id = object_id
|
self.object_id = object_id
|
||||||
self._metadata = metadata
|
self._metadata = metadata
|
||||||
self._file_path = file_path
|
self._file_path = file_path
|
||||||
|
self._destroyed = False
|
||||||
|
self._owns_file = False
|
||||||
|
|
||||||
def get_metadata(self):
|
def get_metadata(self):
|
||||||
if self._metadata is None and not self.object_id is None:
|
if self._metadata is None and not self.object_id is None:
|
||||||
@ -83,10 +86,15 @@ class DSObject:
|
|||||||
def get_file_path(self):
|
def get_file_path(self):
|
||||||
if self._file_path is None and not self.object_id is None:
|
if self._file_path is None and not self.object_id is None:
|
||||||
self.set_file_path(dbus_helpers.get_filename(self.object_id))
|
self.set_file_path(dbus_helpers.get_filename(self.object_id))
|
||||||
|
self._owns_file = True
|
||||||
return self._file_path
|
return self._file_path
|
||||||
|
|
||||||
def set_file_path(self, file_path):
|
def set_file_path(self, file_path):
|
||||||
if self._file_path != file_path:
|
if self._file_path != file_path:
|
||||||
|
if self._file_path and self._owns_file:
|
||||||
|
if os.path.isfile(self._file_path):
|
||||||
|
os.remove(self._file_path)
|
||||||
|
self._owns_file = False
|
||||||
self._file_path = file_path
|
self._file_path = file_path
|
||||||
|
|
||||||
file_path = property(get_file_path, set_file_path)
|
file_path = property(get_file_path, set_file_path)
|
||||||
@ -126,6 +134,26 @@ class DSObject:
|
|||||||
|
|
||||||
activityfactory.create(service_name, handle)
|
activityfactory.create(service_name, handle)
|
||||||
|
|
||||||
|
def destroy(self):
|
||||||
|
logging.debug('DSObject.destroy() file_path: %r.' % self._file_path)
|
||||||
|
if self._destroyed:
|
||||||
|
logging.warning('This DSObject has already been destroyed!.')
|
||||||
|
import pdb;pdb.set_trace()
|
||||||
|
return
|
||||||
|
self._destroyed = True
|
||||||
|
if self._file_path and self._owns_file:
|
||||||
|
logging.debug('Removing temp file: %r' % self._file_path)
|
||||||
|
if os.path.isfile(self._file_path):
|
||||||
|
os.remove(self._file_path)
|
||||||
|
self._owns_file = False
|
||||||
|
self._file_path = None
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if not self._destroyed:
|
||||||
|
logging.warning('DSObject was deleted without cleaning up first. ' \
|
||||||
|
'Please call DSObject.destroy() before disposing it.')
|
||||||
|
self.destroy()
|
||||||
|
|
||||||
def get(object_id):
|
def get(object_id):
|
||||||
logging.debug('datastore.get')
|
logging.debug('datastore.get')
|
||||||
metadata = dbus_helpers.get_properties(object_id)
|
metadata = dbus_helpers.get_properties(object_id)
|
||||||
@ -145,10 +173,6 @@ def write(ds_object, update_mtime=True, reply_handler=None, error_handler=None):
|
|||||||
logging.debug('datastore.write')
|
logging.debug('datastore.write')
|
||||||
|
|
||||||
properties = ds_object.metadata.get_dictionary().copy()
|
properties = ds_object.metadata.get_dictionary().copy()
|
||||||
# The title property should be sent as a 'text' property so it gets indexed
|
|
||||||
if properties.has_key('title'):
|
|
||||||
properties['title:text'] = properties['title']
|
|
||||||
del properties['title']
|
|
||||||
|
|
||||||
if update_mtime:
|
if update_mtime:
|
||||||
properties['mtime'] = datetime.now().isoformat()
|
properties['mtime'] = datetime.now().isoformat()
|
||||||
|
Loading…
Reference in New Issue
Block a user