Fix to mitigate fastresume corruption

The code in develop is more robust but by writing to a temp file first
then moving it should stop the worst of fastresume corruption issues,
e.g. hard resets.
This commit is contained in:
Calum Lind 2014-07-19 18:57:14 +01:00
parent 5d5edd2639
commit c0650f88d1

View File

@ -770,6 +770,7 @@ class TorrentManager(component.Component):
return
path = os.path.join(get_config_dir(), "state", "torrents.fastresume")
path_tmp = path + ".tmp"
# First step is to load the existing file and update the dictionary
if resume_data is None:
@ -780,11 +781,12 @@ class TorrentManager(component.Component):
try:
log.debug("Saving fastresume file: %s", path)
fastresume_file = open(path, "wb")
fastresume_file = open(path_tmp, "wb")
fastresume_file.write(lt.bencode(resume_data))
fastresume_file.flush()
os.fsync(fastresume_file.fileno())
fastresume_file.close()
shutil.move(path_tmp, path)
except IOError:
log.warning("Error trying to save fastresume file")