From 3b9b47011c6b6066e97e0b366474fe7624c3ccef Mon Sep 17 00:00:00 2001 From: John Garland Date: Tue, 20 Jan 2009 13:46:13 +0000 Subject: [PATCH] Fixed regression where blocklist no longer checked for update on startup --- deluge/plugins/blocklist/blocklist/core.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/deluge/plugins/blocklist/blocklist/core.py b/deluge/plugins/blocklist/blocklist/core.py index b26eca02e..432888033 100644 --- a/deluge/plugins/blocklist/blocklist/core.py +++ b/deluge/plugins/blocklist/blocklist/core.py @@ -255,8 +255,14 @@ class Core(CorePluginBase): if os.path.exists(deluge.configmanager.get_config_dir("blocklist.cache")): # Check current block lists time stamp and decide if it needs to be replaced - list_size = long(os.stat(deluge.configmanager.get_config_dir("blocklist.cache")).st_size) - list_time = datetime.datetime.strptime(self.config["file_date"], "%a %b %d %H:%M:%S %Y") + list_stats = os.stat(deluge.configmanager.get_config_dir("blocklist.cache")) + list_size = long(list_stats.st_size) + list_checked = datetime.datetime.fromtimestamp(list_stats.st_mtime) + try: + list_time = datetime.datetime.strptime(self.config["file_date"], "%a %b %d %H:%M:%S %Y") + except: + list_time = list_checked + current_time = datetime.datetime.today() else: log.debug("Blocklist doesn't exist") return True @@ -266,8 +272,9 @@ class Core(CorePluginBase): log.debug("Empty blocklist") return True - # If blocklist has just started up don't check for updates - if not self.has_imported: + # If blocklist has just started up, check for updates if over x days + if not self.has_imported and current_time < (list_checked + datetime.timedelta(days=self.config["check_after_days"])): + log.debug("Blocklist doesn't need checking yet") return False import socket @@ -287,5 +294,7 @@ class Core(CorePluginBase): log.debug("Newer blocklist exists (%s & %d vs %s & %d)", remote_time, remote_size, list_time, list_size) return True + # Update last modified time of blocklist + os.utime(deluge.configmanager.get_config_dir("blocklist.cache"), None) log.debug("Blocklist is up to date") return False