mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-02 16:31:11 -05:00
accountsdb: write DB to a temporary file first
This commit is contained in:
parent
f3bfd9ff73
commit
e46915b58d
@ -86,9 +86,11 @@ class AccountsDB():
|
|||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Exports the database to a file."""
|
"""Exports the database to a file."""
|
||||||
|
tmp_filename = self.filename + '.tmp'
|
||||||
try:
|
try:
|
||||||
with open(self.filename, 'wb') as f:
|
with open(tmp_filename, 'wb') as f:
|
||||||
pickle.dump(self.db, f, 2)
|
pickle.dump(self.db, f, 2)
|
||||||
|
os.rename(tmp_filename, self.filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning('%s: Unable to write database: %s', self._plugin_name, e)
|
log.warning('%s: Unable to write database: %s', self._plugin_name, e)
|
||||||
|
|
||||||
|
@ -86,9 +86,11 @@ class AccountsDB():
|
|||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Exports the database to a file."""
|
"""Exports the database to a file."""
|
||||||
|
tmp_filename = self.filename + '.tmp'
|
||||||
try:
|
try:
|
||||||
with open(self.filename, 'wb') as f:
|
with open(tmp_filename, 'wb') as f:
|
||||||
pickle.dump(self.db, f, 2)
|
pickle.dump(self.db, f, 2)
|
||||||
|
os.rename(tmp_filename, self.filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning('%s: Unable to write database: %s', self._plugin_name, e)
|
log.warning('%s: Unable to write database: %s', self._plugin_name, e)
|
||||||
|
|
||||||
|
@ -85,9 +85,11 @@ class AccountsDB():
|
|||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Exports the database to a file."""
|
"""Exports the database to a file."""
|
||||||
|
tmp_filename = self.filename + '.tmp'
|
||||||
try:
|
try:
|
||||||
with open(self.filename, 'wb') as f:
|
with open(tmp_filename, 'wb') as f:
|
||||||
pickle.dump(self.db, f, 2)
|
pickle.dump(self.db, f, 2)
|
||||||
|
os.rename(tmp_filename, self.filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning('%s: Unable to write database: %s', self._plugin_name, e)
|
log.warning('%s: Unable to write database: %s', self._plugin_name, e)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user