[Sugar-devel] Bug or feature? metadata update truncates datastore entry

Daniel Drake dsd at laptop.org
Fri Mar 4 14:34:25 EST 2011


Hi,

This seems to be new behaviour from somewhere after sugar-0.84.
(probably after 0.88 as well)

If you take an entry from the datastore, examine its file path, adjust
metadata and save, you lose your data.

Simple test case:

Take a datastore ID of any item in your journal that you don't mind losing.

Open Terminal activity, run "python" to launch python shell
In shell:

>>> from sugar.datastore import datastore
>>> import dbus
>>> import os

Now lookup the datastore item

>>> obj = datastore.get("fc3e2c72-0ea3-4ddf-977f-cb5299e4d972")
>>> obj
<sugar.datastore.datastore.DSObject object at 0x948c52c>

Retreive its file path, check its size:

>>> path = obj.file_path
>>> path
dbus.String(u'/home/olpc/.sugar/default/data/fc3e2c72-0ea3-4ddf-977f-cb5299e4d972_B1OFZW.png')
>>> os.path.getsize(path)
10474L

Change the metadata:

>>> obj.metadata['title'] = dbus.ByteArray("my new title")

Now save:

>>> datastore.write(obj)

Now observe truncated file:

>>> os.path.getsize(path)
0L

bye bye data :(

The net effect of this is that if you change the title of a photo in
record, you lose your photo.

Daniel


More information about the Sugar-devel mailing list