Pause transfers until blocklist is imported (#861)

This commit is contained in:
John Garland 2010-04-12 00:40:23 +10:00
parent f21dd242f6
commit 35dfcf3a77
2 changed files with 14 additions and 0 deletions

View File

@ -8,6 +8,7 @@
==== Blocklist ==== ==== Blocklist ====
* Implement local blocklist support * Implement local blocklist support
* #861: Pause transfers until blocklist is imported
==== Web ==== ==== Web ====
* Migrate to ExtJS 3.1 * Migrate to ExtJS 3.1

View File

@ -323,6 +323,7 @@ class Core(CorePluginBase):
log.debug("Latest blocklist is already imported") log.debug("Latest blocklist is already imported")
return defer.succeed(blocklist) return defer.succeed(blocklist)
self.pause_transfers()
self.is_importing = True self.is_importing = True
self.num_blocked = 0 self.num_blocked = 0
self.blocklist = self.core.session.get_ip_filter() self.blocklist = self.core.session.get_ip_filter()
@ -362,6 +363,7 @@ class Core(CorePluginBase):
else: else:
log.debug("Copying %s to %s", blocklist, cache) log.debug("Copying %s to %s", blocklist, cache)
d = threads.deferToThread(shutil.copy, blocklist, cache) d = threads.deferToThread(shutil.copy, blocklist, cache)
self.resume_transfers()
return d return d
def on_import_error(self, f): def on_import_error(self, f):
@ -394,6 +396,8 @@ class Core(CorePluginBase):
if try_again: if try_again:
d = self.import_list(blocklist) d = self.import_list(blocklist)
d.addCallbacks(self.on_import_complete, self.on_import_error) d.addCallbacks(self.on_import_complete, self.on_import_error)
else:
self.resume_transfers()
return d return d
@ -413,3 +417,12 @@ class Core(CorePluginBase):
raise UnknownFormatError raise UnknownFormatError
else: else:
self.reader = create_reader(self.config["list_type"], self.config["list_compression"]) self.reader = create_reader(self.config["list_type"], self.config["list_compression"])
def pause_transfers(self):
self.session_was_paused = self.core.session.is_paused()
if not self.session_was_paused:
self.core.session.pause()
def resume_transfers(self):
if not self.session_was_paused:
self.core.session.resume()