From 0697728b068cec6b16c7eb909b0a5213c4a2aa19 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Thu, 04 Oct 2007 17:06:15 +0000 Subject: #3180: Recreate the index on mount failure of only removable devices. --- diff --git a/NEWS b/NEWS index d4b7143..ef3bdcf 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +* #3180: Recreate the index on mount failure of only removable devices. (tomeu) + Snapshot dce9c18d56 * #3469 Human readable names on USB. (marco) diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py index b1ecbef..8d5909c 100644 --- a/src/olpc/datastore/backingstore.py +++ b/src/olpc/datastore/backingstore.py @@ -20,6 +20,8 @@ import subprocess import time import threading +import xapian + from olpc.datastore.xapianindex import IndexManager from olpc.datastore import bin_copy from olpc.datastore import utils @@ -598,7 +600,25 @@ class InplaceFileBackingStore(FileBackingStore): def load(self): - super(InplaceFileBackingStore, self).load() + try: + super(InplaceFileBackingStore, self).load() + except xapian.DatabaseCorruptError, e: + # TODO: Try to recover in a smarter way than deleting the base + # dir and reinitializing the index. + + logging.error('Error while trying to load mount point %s: %s. ' \ + 'Will try to renitialize and load again.' % (self.base, e)) + + # Delete the base dir and its contents + for root, dirs, files in os.walk(self.base, topdown=False): + for name in files: + os.remove(os.path.join(root, name)) + os.rmdir(root) + + self.initialize() + self.load() + return + # now map/update the existing data into the indexes # but do it async self.walker = threading.Thread(target=self._walk) -- cgit v0.9.1