do not overwrite old backup until new backup is done

This commit is contained in:
Dominik Demuth 2023-11-09 17:05:17 +01:00
parent 5ea1ed6d0a
commit 070509c691
2 changed files with 12 additions and 4 deletions

View File

@ -1095,7 +1095,10 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
def _autosave(self): def _autosave(self):
# TODO better separate thread may it takes some time to save # TODO better separate thread may it takes some time to save
self.status.setText('Autosave...') self.status.setText('Autosave...')
NMRWriter(self.management.graphs, self.management.data).export(self.__backup_path) success = NMRWriter(self.management.graphs, self.management.data).export(self.__backup_path.with_suffix('.nmr.0'))
if success:
self.__backup_path.with_suffix('.nmr.0').rename(self.__backup_path)
self.status.setText('') self.status.setText('')
def check_for_backup(self): def check_for_backup(self):

View File

@ -22,6 +22,11 @@ class NMRWriter:
if isinstance(fname, str): if isinstance(fname, str):
fname = Path(fname) fname = Path(fname)
with fname.open(mode='wb') as fh: try:
fh.write(pack('16s', b'NMREVAL' + bytes(__version__, 'utf8'))) with fname.open(mode='wb') as fh:
dump(self._states, fh) fh.write(pack('16s', b'NMREVAL' + bytes(__version__, 'utf8')))
dump(self._states, fh)
return True
except Exception as e:
print(f'Saving {fname} failed with exception {e.args}')
return False