From 450426576e1e0820a4d41878581e06e210401616 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Tue, 7 Apr 2009 07:31:00 +0000 Subject: [PATCH] If cache is corrupted than delete it, it will be recreated when needed. --- pisi/db/lazydb.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pisi/db/lazydb.py b/pisi/db/lazydb.py index c618753e..6728a5d2 100644 --- a/pisi/db/lazydb.py +++ b/pisi/db/lazydb.py @@ -43,9 +43,16 @@ class LazyDB(Singleton): file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'wb'), 1) def cache_load(self): - if os.path.exists("/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()): - self._instance().__dict__ = cPickle.load(file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'rb')) - return True + cache_file = "/var/cache/pisi/%s.cache" % self.__class__.__name__.lower() + if os.path.exists(cache_file): + try: + self._instance().__dict__ = cPickle.load(file(cache_file, 'rb')) + return True + except cPickle.UnpicklingError: + # Delete corrupted cache + if os.access("/var/cache/pisi", os.W_OK): + os.unlink(cache_file) + return False return False def cache_flush(self):