Browse Source

Storage: make an auto-backup

Helge Jung 9 years ago
parent
commit
3db322ca2c
2 changed files with 7 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 6 0
      ffstatus/storage.py

+ 1 - 0
.gitignore

@@ -7,6 +7,7 @@
 
 # storage
 storage.dat
+storage.dat.autobackup
 
 # dummy scripts + datafiles
 alfred*json

+ 6 - 0
ffstatus/storage.py

@@ -4,6 +4,7 @@
 import cPickle as pickle
 import logging
 import os
+import shutil
 
 from .basestorage import BaseStorage
 
@@ -49,6 +50,11 @@ class Storage(BaseStorage):
         pickle.dump(self.data, self.storage_file, protocol=2)
         self.storage_file.flush()
 
+        # make an auto-backup of the just-written file
+        shutil.copyfile(
+            self.storage_filename,
+            self.storage_filename + '.autobackup')
+
     def close(self):
         self.save()
         self.storage_file.close()