From c0650f88d15bbe84b4aeaaebb309f4bf1cefe17f Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sat, 19 Jul 2014 18:57:14 +0100 Subject: 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. --- deluge/core/torrentmanager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index c9836aab6..ab702cda3 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -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") -- cgit