[Sugar-devel] [PATCH 6/7] datastore: make delete() more reliable, log properly

Martin Langhoff martin at laptop.org
Thu Sep 20 23:55:39 EDT 2012


 - use try/except to catch and log errors in datastore.log
   (instead of echoing them to callers over dbus)

 - use rmtree() to more reliably remove the entry

 - get_entry_path() before we delete all the related
   metadata.

Signed-off-by: Martin Langhoff <martin at laptop.org>
---
 src/carquinyol/datastore.py |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 33c658d..01d175e 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -430,14 +430,22 @@ class DataStore(dbus.service.Object):
              out_signature='')
     def delete(self, uid):
         self._mark_dirty()
-        self._optimizer.remove(uid)
-
-        self._index_store.delete(uid)
-        self._file_store.delete(uid)
-        self._metadata_store.delete(uid)
-
-        entry_path = layoutmanager.get_instance().get_entry_path(uid)
-        os.removedirs(entry_path)
+        try:
+            entry_path = layoutmanager.get_instance().get_entry_path(uid)
+            self._optimizer.remove(uid)
+            self._index_store.delete(uid)
+            self._file_store.delete(uid)
+            self._metadata_store.delete(uid)
+            # remove the dirtree
+            shutil.rmtree(entry_path)
+            try:
+                # will remove the hashed dir if nothing else is there
+                os.removedirs(os.path.dirname(entry_path))
+            except:
+                pass
+        except:
+            logger.exception('Exception deleting entry')
+            raise
 
         self.Deleted(uid)
         logger.debug('deleted %s', uid)
-- 
1.7.10.4



More information about the Sugar-devel mailing list