Add flush_disk_cache parameter to save_resume_data
Using this flag avoids potential issue with file timestamps and is only needed when stopping the session.
This commit is contained in:
parent
f2535e196d
commit
bc7380c5d7
@ -1034,12 +1034,18 @@ class Torrent(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save_resume_data(self):
|
def save_resume_data(self, flush_disk_cache=False):
|
||||||
"""Signals libtorrent to build resume data for this torrent.
|
"""Signals libtorrent to build resume data for this torrent.
|
||||||
|
|
||||||
The response is returned in a libtorrent alert.
|
Params:
|
||||||
|
flush_disk_cache (bool): Avoids potential issue with file timestamps
|
||||||
|
and is only needed when stopping the session.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None: The response with resume data is returned in a libtorrent save_resume_data_alert.
|
||||||
"""
|
"""
|
||||||
self.handle.save_resume_data()
|
flags = lt.save_resume_flags_t.flush_disk_cache if flush_disk_cache else 0
|
||||||
|
self.handle.save_resume_data(flags)
|
||||||
|
|
||||||
def write_torrentfile(self):
|
def write_torrentfile(self):
|
||||||
"""Writes the torrent file to the state directory in config"""
|
"""Writes the torrent file to the state directory in config"""
|
||||||
|
|||||||
@ -268,7 +268,7 @@ class TorrentManager(component.Component):
|
|||||||
if result and os.path.isfile(self.temp_file):
|
if result and os.path.isfile(self.temp_file):
|
||||||
os.remove(self.temp_file)
|
os.remove(self.temp_file)
|
||||||
|
|
||||||
d = self.save_resume_data()
|
d = self.save_resume_data(flush_disk_cache=True)
|
||||||
d.addCallback(remove_temp_file)
|
d.addCallback(remove_temp_file)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -753,29 +753,33 @@ class TorrentManager(component.Component):
|
|||||||
# We return True so that the timer thread will continue
|
# We return True so that the timer thread will continue
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save_resume_data(self, torrent_ids=None):
|
def save_resume_data(self, torrent_ids=None, flush_disk_cache=False):
|
||||||
"""Saves resume data for list of torrent_ids or for all torrents
|
"""Saves resume data for list of torrent_ids or for all torrents
|
||||||
needing resume data updated if torrent_ids is None
|
needing resume data updated if torrent_ids is None
|
||||||
|
|
||||||
:returns: A Deferred whose callback will be invoked when save is complete
|
Params:
|
||||||
:rtype: twisted.internet.defer.Deferred
|
torrent_ids (list of str) (
|
||||||
|
flush_disk_cache (bool): Avoids potential issue with file timestamps
|
||||||
|
and is only needed when stopping the session.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
t.i.d.DeferredList: A list of twisted Deferred callbacks that will
|
||||||
|
be invoked when save is complete.
|
||||||
"""
|
"""
|
||||||
if torrent_ids is None:
|
if torrent_ids is None:
|
||||||
torrent_ids = (t[0] for t in self.torrents.iteritems() if t[1].handle.need_save_resume_data())
|
torrent_ids = (t[0] for t in self.torrents.iteritems() if t[1].handle.need_save_resume_data())
|
||||||
|
|
||||||
deferreds = []
|
|
||||||
|
|
||||||
def on_torrent_resume_save(dummy_result, torrent_id):
|
def on_torrent_resume_save(dummy_result, torrent_id):
|
||||||
self.waiting_on_resume_data.pop(torrent_id, None)
|
self.waiting_on_resume_data.pop(torrent_id, None)
|
||||||
|
|
||||||
|
deferreds = []
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
d = self.waiting_on_resume_data.get(torrent_id)
|
d = self.waiting_on_resume_data.get(torrent_id)
|
||||||
if not d:
|
if not d:
|
||||||
d = Deferred().addBoth(on_torrent_resume_save, torrent_id)
|
d = Deferred().addBoth(on_torrent_resume_save, torrent_id)
|
||||||
self.waiting_on_resume_data[torrent_id] = d
|
self.waiting_on_resume_data[torrent_id] = d
|
||||||
deferreds.append(d)
|
deferreds.append(d)
|
||||||
self.torrents[torrent_id].save_resume_data()
|
self.torrents[torrent_id].save_resume_data(flush_disk_cache)
|
||||||
|
|
||||||
def on_all_resume_data_finished(result):
|
def on_all_resume_data_finished(result):
|
||||||
if result:
|
if result:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user