Check installdb cache's validity before using cache file.
This commit is contained in:
@@ -65,7 +65,7 @@ class InstallInfo:
|
|||||||
class InstallDB(lazydb.LazyDB):
|
class InstallDB(lazydb.LazyDB):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
lazydb.LazyDB.__init__(self, cacheable=True)
|
lazydb.LazyDB.__init__(self, cacheable=True, cachedir=ctx.config.packages_dir())
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.installed_db = self.__generate_installed_pkgs()
|
self.installed_db = self.__generate_installed_pkgs()
|
||||||
|
|||||||
+15
-2
@@ -11,6 +11,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
import stat
|
||||||
import cPickle
|
import cPickle
|
||||||
import time
|
import time
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
@@ -35,10 +37,11 @@ class Singleton(object):
|
|||||||
del self._the_instances[type(self).__name__]
|
del self._the_instances[type(self).__name__]
|
||||||
|
|
||||||
class LazyDB(Singleton):
|
class LazyDB(Singleton):
|
||||||
def __init__(self, cacheable=False):
|
def __init__(self, cacheable=False, cachedir=None):
|
||||||
if not self.__dict__.has_key("initialized"):
|
if not self.__dict__.has_key("initialized"):
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
self.cacheable = cacheable
|
self.cacheable = cacheable
|
||||||
|
self.cachedir = cachedir
|
||||||
|
|
||||||
def is_initialized(self):
|
def is_initialized(self):
|
||||||
return self.initialized
|
return self.initialized
|
||||||
@@ -51,8 +54,18 @@ class LazyDB(Singleton):
|
|||||||
cPickle.dump(self._instance().__dict__,
|
cPickle.dump(self._instance().__dict__,
|
||||||
file(self.__cache_file(), 'wb'), 1)
|
file(self.__cache_file(), 'wb'), 1)
|
||||||
|
|
||||||
|
def cache_valid(self):
|
||||||
|
if not self.cachedir:
|
||||||
|
return True
|
||||||
|
if not os.path.exists(self.cachedir):
|
||||||
|
return False
|
||||||
|
cache_modified = os.stat(self.__cache_file()).st_mtime
|
||||||
|
cache_dir_modified = os.stat(self.cachedir).st_mtime
|
||||||
|
valid = cache_modified > cache_dir_modified
|
||||||
|
return valid
|
||||||
|
|
||||||
def cache_load(self):
|
def cache_load(self):
|
||||||
if os.path.exists(self.__cache_file()):
|
if os.path.exists(self.__cache_file()) and self.cache_valid():
|
||||||
try:
|
try:
|
||||||
self._instance().__dict__ = cPickle.load(file(self.__cache_file(), 'rb'))
|
self._instance().__dict__ = cPickle.load(file(self.__cache_file(), 'rb'))
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user