Support moving of files to datastore when using write_file()

Using the transfer_ownership argument, activities using the default activity
datastore integration methods (namely write_file) will now tell the datastore
that it can move the files by default.  This reduces the copies required, which
is slow on flash.  For activities not using the standard APIs (Record, etc),
the datastore bindings allow the activity to specify when ownership should
transfer.
This commit is contained in:
Dan Williams 2007-09-07 21:53:32 -04:00
parent 434483f54a
commit 9e2a9c4c02
4 changed files with 19 additions and 7 deletions

3
NEWS
View File

@ -1,3 +1,6 @@
* Support moving of data files written to the datastore using standard Activity
write_file() API (dcbw)
Snapshot c8700feccf Snapshot c8700feccf
* Removing activity from donut when not the active and the last one (erikos) * Removing activity from donut when not the active and the last one (erikos)

View File

@ -487,6 +487,7 @@ class Activity(Window, gtk.Container):
pass pass
self._updating_jobject = True self._updating_jobject = True
datastore.write(self._jobject, datastore.write(self._jobject,
transfer_ownership=True,
reply_handler=self._internal_save_cb, reply_handler=self._internal_save_cb,
error_handler=self._internal_save_error_cb) error_handler=self._internal_save_error_cb)

View File

@ -186,7 +186,7 @@ def create():
metadata['mtime'] = metadata['ctime'] metadata['mtime'] = metadata['ctime']
return DSObject(object_id=None, metadata=metadata, file_path=None) return DSObject(object_id=None, metadata=metadata, file_path=None)
def write(ds_object, update_mtime=True, reply_handler=None, error_handler=None, timeout=-1): def write(ds_object, update_mtime=True, transfer_ownership=False, reply_handler=None, error_handler=None, timeout=-1):
logging.debug('datastore.write') logging.debug('datastore.write')
properties = ds_object.metadata.get_dictionary().copy() properties = ds_object.metadata.get_dictionary().copy()
@ -198,12 +198,14 @@ def write(ds_object, update_mtime=True, reply_handler=None, error_handler=None,
dbus_helpers.update(ds_object.object_id, dbus_helpers.update(ds_object.object_id,
properties, properties,
ds_object.file_path, ds_object.file_path,
transfer_ownership,
reply_handler=reply_handler, reply_handler=reply_handler,
error_handler=error_handler, error_handler=error_handler,
timeout=timeout) timeout=timeout)
else: else:
ds_object.object_id = dbus_helpers.create(properties, ds_object.object_id = dbus_helpers.create(properties,
ds_object.file_path) ds_object.file_path,
transfer_ownership)
# TODO: register the object for updates # TODO: register the object for updates
logging.debug('Written object %s to the datastore.' % ds_object.object_id) logging.debug('Written object %s to the datastore.' % ds_object.object_id)

View File

@ -40,20 +40,26 @@ def _get_data_store():
DS_DBUS_INTERFACE) DS_DBUS_INTERFACE)
return _data_store return _data_store
def create(properties, filename): def create(properties, filename, transfer_ownership=False):
object_id = _get_data_store().create(dbus.Dictionary(properties), filename) object_id = _get_data_store().create(dbus.Dictionary(properties), filename,
transfer_ownership)
logging.debug('dbus_helpers.create: ' + object_id) logging.debug('dbus_helpers.create: ' + object_id)
return object_id return object_id
def update(uid, properties, filename, reply_handler=None, error_handler=None, timeout=-1): def update(uid, properties, filename, transfer_ownership=False,
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, filename, properties)) reply_handler=None, error_handler=None, timeout=-1):
debug_props = properties.copy()
if debug_props.has_key("preview"):
debug_props["preview"] = "<omitted>"
logging.debug('dbus_helpers.update: %s, %s, %s, %s' % (uid, filename, debug_props, transfer_ownership))
if reply_handler and error_handler: if reply_handler and error_handler:
_get_data_store().update(uid, dbus.Dictionary(properties), filename, _get_data_store().update(uid, dbus.Dictionary(properties), filename,
transfer_ownership,
reply_handler=reply_handler, reply_handler=reply_handler,
error_handler=error_handler, error_handler=error_handler,
timeout=timeout) timeout=timeout)
else: else:
_get_data_store().update(uid, dbus.Dictionary(properties), filename) _get_data_store().update(uid, dbus.Dictionary(properties), filename, transfer_ownership)
def delete(uid): def delete(uid):
logging.debug('dbus_helpers.delete: %r' % uid) logging.debug('dbus_helpers.delete: %r' % uid)