diff --git a/deluge/config.py b/deluge/config.py index 52b22c6a4..510dbce08 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -270,13 +270,26 @@ class Config(object): self.__save_timer = None + # Save the new config and make sure it's written to disk try: log.debug("Saving new config file %s", filename + ".new") - json.dump(self.__config, open(filename + ".new", "w"), indent=2) + f = open(filename + ".new", "w") + json.dump(self.__config, f, indent=2) + f.flush() + os.fsync(f.fileno()) + f.close() except Exception, e: log.error("Error writing new config file: %s", e) return + # Make a backup of the old config + try: + log.debug("Backing up old config file to %s~", filename) + shutil.move(filename, filename + "~") + except Exception, e: + log.error("Error backing up old config..") + return + # The new config file has been written successfully, so let's move it over # the existing one. try: