Fix race condition when blocklist is up to date.

Make import_list return a deferred to prevent error (still doesn't do anything).
Fix typos.
This commit is contained in:
John Garland 2009-07-07 06:51:47 +00:00
commit 6a78e51475

View file

@ -39,7 +39,7 @@ import datetime
import shutil import shutil
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
from twisted.internet import reactor, threads from twisted.internet import reactor, threads, defer
from twisted.web import error from twisted.web import error
from deluge.log import LOG as log from deluge.log import LOG as log
@ -222,10 +222,10 @@ class Core(CorePluginBase):
else: else:
if "Not Modified" in error_msg: if "Not Modified" in error_msg:
log.debug("Blocklist is up-to-date!") log.debug("Blocklist is up-to-date!")
d = threads.deferToThread(update_info,
deluge.configmanager.get_config_dir("blocklist.cache"))
self.up_to_date = True self.up_to_date = True
self.use_cache = True self.use_cache = True
d = threads.deferToThread(update_info,
deluge.configmanager.get_config_dir("blocklist.cache"))
f.trap(f.type) f.trap(f.type)
elif self.failed_attempts < self.config["try_times"]: elif self.failed_attempts < self.config["try_times"]:
log.warning("Blocklist download failed!") log.warning("Blocklist download failed!")
@ -247,6 +247,8 @@ class Core(CorePluginBase):
# TODO: Open blocklist with appropriate reader # TODO: Open blocklist with appropriate reader
# TODO: Import ranges # TODO: Import ranges
return defer.succeed(None)
def on_import_complete(self, result): def on_import_complete(self, result):
"""Runs any import clean up functions""" """Runs any import clean up functions"""
d = None d = None
@ -254,7 +256,8 @@ class Core(CorePluginBase):
self.has_imported = True self.has_imported = True
log.debug("Blocklist import complete!") log.debug("Blocklist import complete!")
# Move downloaded blocklist to cache # Move downloaded blocklist to cache
if not self.use_cache: if not self.use_cache and not self.up_to_date:
log.debug("Moving blocklist.download to blocklist.cache")
d = threads.deferToThread(shutil.move, d = threads.deferToThread(shutil.move,
deluge.configmanager.get_config_dir("blocklist.download"), deluge.configmanager.get_config_dir("blocklist.download"),
deluge.configmanager.get_config_dir("blocklist.cache")) deluge.configmanager.get_config_dir("blocklist.cache"))
@ -270,5 +273,5 @@ class Core(CorePluginBase):
e = f.trap(Exception) e = f.trap(Exception)
log.warning("Error reading blocklist: ", e) log.warning("Error reading blocklist: ", e)
d = self.import_list() d = self.import_list()
d.addCallbacks(on_import_complete, on_import_error) d.addCallbacks(self.on_import_complete, self.on_import_error)
return d return d