diff --git a/gajim/common/optparser.py b/gajim/common/optparser.py index d300d61c5..38f0d5f4f 100644 --- a/gajim/common/optparser.py +++ b/gajim/common/optparser.py @@ -111,24 +111,18 @@ class OptionsParser: (base_dir, filename) = os.path.split(self.__filename) self.__tempfile = os.path.join(base_dir, '.' + filename) try: - f = os.fdopen(os.open(self.__tempfile, - os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0o600), 'w', encoding='utf-8') + with open(self.__tempfile, 'w', encoding='utf-8') as f: + app.config.foreach(self.write_line, f) except IOError as e: return str(e) - try: - app.config.foreach(self.write_line, f) - except IOError as e: - return str(e) - f.flush() - os.fsync(f.fileno()) - f.close() + if os.path.exists(self.__filename): if os.name == 'nt': # win32 needs this try: os.remove(self.__filename) - except Exception: - pass + except Exception as e: + return str(e) try: os.rename(self.__tempfile, self.__filename) except IOError as e: diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index 69eaf945e..0b0fee886 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -2408,8 +2408,9 @@ class Interface: print(err_str, file=sys.stderr) # it is good to notify the user # in case he or she cannot see the output of the console - dialogs.ErrorDialog(_('Could not save your settings and ' + error_dialog = dialogs.ErrorDialog(_('Could not save your settings and ' 'preferences'), err_str) + error_dialog.run() sys.exit() @staticmethod