if filename.lower() in TRACKED_FILES:
log.msg("Registering package file: "+cache_path)
self.packages[cache_path] = file_path
+ self.packages.sync()
return True
return False
if not self.packages[f].exists():
log.msg("File in packages database has been deleted: "+f)
del self.packages[f]
+ self.packages.sync()
#{ Dictionary interface details
def __getitem__(self, key): return self.packages[key]
@type loading: L{twisted.internet.defer.Deferred}
@ivar loading: if the cache is currently being loaded, this will be
called when it is loaded, otherwise it is None
+ @type loading_unload: C{boolean}
+ @ivar loading_unload: whether there is an unload pending on the current load
@type unload_later: L{twisted.internet.interfaces.IDelayedCall}
@ivar unload_later: the delayed call to unload the apt cache
@type indexrecords: C{dictionary}
self.packages = PackageFileList(cache_dir)
self.loaded = False
self.loading = None
+ self.loading_unload = False
self.unload_later = None
def __del__(self):
self.unload_later.reset(config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'))
else:
self.unload_later = reactor.callLater(config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'), self.unload)
-
+
+ # Check if it's already loaded
+ if self.loaded:
+ return defer.succeed(True)
+
# Make sure it's not already being loaded
if self.loading is None:
log.msg('Loading the packages cache')
+ self.loading_unload = False
self.loading = threads.deferToThread(self._load)
self.loading.addCallback(self.doneLoading)
return self.loading
def doneLoading(self, loadResult):
"""Cache is loaded."""
self.loading = None
+
+ # Check for a pending unload
+ if self.loading_unload:
+ log.msg('Re-loading the packages cache')
+ self.unload()
+ self.loading_unload = False
+ self.loading = threads.deferToThread(self._load)
+ self.loading.addCallback(self.doneLoading)
+ return self.loading
+
# Must pass on the result for the next callback
return loadResult
if self.unload_later and self.unload_later.active():
self.unload_later.cancel()
self.unload_later = None
- if self.loaded:
+ if self.loading:
+ self.loading_unload = True
+ elif self.loaded:
log.msg('Unloading the packages cache')
# This should save memory
del self.cache