Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <silbe@activitycentral.com>2011-11-02 22:05:36 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2011-12-20 13:34:16 (GMT)
commita73d60aed5d500de61b0bcf3ca007c1531bd4ee2 (patch)
treea327ea1382e9465e398af2770e9528fe0305dc6d
parent5451d64086a6582b39b4f7baf511534399a809f6 (diff)
Ensure we return valid internal / calculated propertieswip
The copy in the metadata storage can get corrupted, e.g. due to low level crashes or running out of battery (see OLPC#11372 [1] for a real-life example). This is especially problematic for the uid property, since without it the caller (i.e. the Journal) can't even figure out which entry to delete. [1] https://dev.laptop.org/ticket/11372 Reported-by: Gary Martin <garycmartin@googlemail.com> Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
-rw-r--r--src/carquinyol/datastore.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 4f3faba..eafc8e1 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -333,6 +333,7 @@ class DataStore(dbus.service.Object):
return self._find_all(query, properties)
metadata = self._metadata_store.retrieve(uid, properties)
+ self._fill_internal_props(metadata, uid, properties)
entries.append(metadata)
logger.debug('find(): %r', time.time() - t)
@@ -350,10 +351,28 @@ class DataStore(dbus.service.Object):
entries = []
for uid in uids:
metadata = self._metadata_store.retrieve(uid, properties)
+ self._fill_internal_props(metadata, uid, properties)
entries.append(metadata)
return entries, count
+ def _fill_internal_props(self, metadata, uid, names=None):
+ """Fill in internal / computed properties in metadata
+
+ Properties are only set if they appear in names or if names is
+ empty.
+ """
+ if not names or 'uid' in names:
+ metadata['uid'] = uid
+
+ if not names or 'filesize' in names:
+ file_path = self._file_store.get_file_path(uid)
+ if os.path.exists(file_path):
+ stat = os.stat(file_path)
+ metadata['filesize'] = str(stat.st_size)
+ else:
+ metadata['filesize'] = '0'
+
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='s',
out_signature='s',
@@ -376,6 +395,7 @@ class DataStore(dbus.service.Object):
def get_properties(self, uid):
logging.debug('datastore.get_properties %r', uid)
metadata = self._metadata_store.retrieve(uid)
+ self._fill_internal_props(metadata, uid)
return metadata
@dbus.service.method(DS_DBUS_INTERFACE,