#5707 BLOC Update.: Previews are not deleted when their matching datastore objects are removed

Zarro Boogs per Child bugtracker at laptop.org
Tue Jan 8 11:47:20 EST 2008


#5707: Previews are not deleted when their matching datastore objects are removed
------------------------+---------------------------------------------------
  Reporter:  Phil       |       Owner:  tomeu    
      Type:  defect     |      Status:  new      
  Priority:  blocker    |   Milestone:  Update.1 
 Component:  datastore  |     Version:  Build 650
Resolution:             |    Keywords:  review?  
  Verified:  0          |    Blocking:           
 Blockedby:             |  
------------------------+---------------------------------------------------

Comment(by tomeu):

 What about this?

 I don't like adding a dependency from backingstore.py to model.py, but
 that's the best I could think of.

 {{{
 diff --git a/src/olpc/datastore/backingstore.py
 b/src/olpc/datastore/backingstore.py
 index 1af0088..fd2c4b8 100644
 --- a/src/olpc/datastore/backingstore.py
 +++ b/src/olpc/datastore/backingstore.py
 @@ -32,6 +32,7 @@ import gobject
  from olpc.datastore.xapianindex import IndexManager
  from olpc.datastore import bin_copy
  from olpc.datastore import utils
 +from olpc.datastore import model

  # changing this pattern impacts _targetFile
  filename_attempt_pattern = re.compile('\(\d+\)$')
 @@ -600,6 +601,13 @@ class FileBackingStore(BackingStore):
              self.indexmanager.index(props)

      def delete(self, uid, allowMissing=True):
 +        external_properties =
 model.defaultModel.get_external_properties()
 +        for property_name in external_properties:
 +            file_path = os.path.join(self.base, property_name, uid)
 +            if os.path.exists(file_path):
 +                logging.debug('deleting external property: %r' %
 file_path)
 +                os.unlink(file_path)
 +
          self.indexmanager.delete(uid)
          path = self._translatePath(uid)
          if os.path.exists(path):
 diff --git a/src/olpc/datastore/model.py b/src/olpc/datastore/model.py
 index bb8228a..e4a3e3b 100644
 --- a/src/olpc/datastore/model.py
 +++ b/src/olpc/datastore/model.py
 @@ -170,6 +170,13 @@ class Model(object):
              args = self.fields[fn]
              addField(args[0], **args[2])

 +    def get_external_properties(self):
 +        external_properties = []
 +        for field_name in self.fields:
 +            field = self.fields.get(field_name)
 +            if field[1] == "external":
 +                external_properties.append(field[0])
 +        return external_properties

  # Properties we don't automatically include in properties dict
  EXCLUDED_PROPERTIES = ['fulltext', ]
 }}}

-- 
Ticket URL: <http://dev.laptop.org/ticket/5707#comment:10>
One Laptop Per Child <http://dev.laptop.org>
OLPC bug tracking system



More information about the Bugs mailing list