diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2017-01-11 12:58:15 +0000 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2017-01-17 09:20:11 +0000 |
commit | 78851becf21bd66493419e8d0def24e9c57248bb (patch) | |
tree | f204c005314cbf48e072735c5e3635f5787288ce | |
parent | af76abb038660857da0d9a533e8a208dc0285335 (diff) | |
download | deluge-78851becf21bd66493419e8d0def24e9c57248bb.tar.gz deluge-78851becf21bd66493419e8d0def24e9c57248bb.tar.bz2 deluge-78851becf21bd66493419e8d0def24e9c57248bb.zip |
[#2946] Workaround 1.1 libtorrent default piece priority
* The default piece priority was changed in lt 1.1 from 1 to 4
so in 1.3 we will simple convert them back to 1 as 4 is not used.
* The set_file_priorities method was refactored to make the changes simpler.
-rw-r--r-- | deluge/core/torrent.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index aaa6f7640..578fd1b69 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -310,19 +310,19 @@ class Torrent(object): self.options["move_completed_path"] = move_completed_path def set_file_priorities(self, file_priorities): - if len(file_priorities) != len(self.get_files()): - log.debug("file_priorities len != num_files") - self.options["file_priorities"] = self.handle.file_priorities() - return - - if self.options["compact_allocation"]: - log.debug("setting file priority with compact allocation does not work!") - self.options["file_priorities"] = self.handle.file_priorities() - return + handle_file_priorities = self.handle.file_priorities() + # Workaround for libtorrent 1.1 changing default priorities from 1 to 4. + if 4 in handle_file_priorities: + handle_file_priorities = [1 if x == 4 else x for x in handle_file_priorities] log.debug("setting %s's file priorities: %s", self.torrent_id, file_priorities) - self.handle.prioritize_files(file_priorities) + if (self.handle.has_metadata() and not self.options["compact_allocation"] and + file_priorities and len(file_priorities) == len(self.get_files())): + self.handle.prioritize_files(file_priorities) + else: + log.debug("Unable to set new file priorities.") + file_priorities = handle_file_priorities if 0 in self.options["file_priorities"]: # We have previously marked a file 'Do Not Download' @@ -334,7 +334,7 @@ class Torrent(object): self.update_state() break - self.options["file_priorities"] = self.handle.file_priorities() + self.options["file_priorities"] = handle_file_priorities if self.options["file_priorities"] != list(file_priorities): log.warning("File priorities were not set for this torrent") |