mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Fixed the issues with backup files that were the exact same as the original.
This commit is contained in:
parent
b19a2bb051
commit
8fd64a6325
23
src/ircdb.py
23
src/ircdb.py
@ -528,6 +528,7 @@ class IrcChannelCreator(Creator):
|
|||||||
class UsersDictionary(utils.IterableMap):
|
class UsersDictionary(utils.IterableMap):
|
||||||
"""A simple serialized-to-file User Database."""
|
"""A simple serialized-to-file User Database."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.noFlush = False
|
||||||
self.filename = None
|
self.filename = None
|
||||||
self.users = {}
|
self.users = {}
|
||||||
self.nextId = 0
|
self.nextId = 0
|
||||||
@ -538,11 +539,17 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
def open(self, filename):
|
def open(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
reader = unpreserve.Reader(IrcUserCreator, self)
|
reader = unpreserve.Reader(IrcUserCreator, self)
|
||||||
|
try:
|
||||||
|
self.noFlush = True
|
||||||
try:
|
try:
|
||||||
reader.readFile(filename)
|
reader.readFile(filename)
|
||||||
|
self.noFlush = False
|
||||||
|
self.flush()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.error('Invalid user dictionary file, starting from scratch.')
|
log.error('Invalid user dictionary file, resetting to empty.')
|
||||||
log.error('Exact error: %s', utils.exnToString(e))
|
log.error('Exact error: %s', utils.exnToString(e))
|
||||||
|
finally:
|
||||||
|
self.noFlush = False
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""Reloads the database from its file."""
|
"""Reloads the database from its file."""
|
||||||
@ -560,6 +567,7 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Flushes the database to its file."""
|
"""Flushes the database to its file."""
|
||||||
|
if not self.noFlush:
|
||||||
if self.filename is not None:
|
if self.filename is not None:
|
||||||
L = self.users.items()
|
L = self.users.items()
|
||||||
L.sort()
|
L.sort()
|
||||||
@ -682,7 +690,8 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
raise ValueError, s
|
raise ValueError, s
|
||||||
self.invalidateCache(id)
|
self.invalidateCache(id)
|
||||||
self.users[id] = user
|
self.users[id] = user
|
||||||
self.flush()
|
# This shouldn't happen; we flush automatically every once in awhile.
|
||||||
|
#self.flush()
|
||||||
|
|
||||||
def delUser(self, id):
|
def delUser(self, id):
|
||||||
"""Removes a user from the database."""
|
"""Removes a user from the database."""
|
||||||
@ -709,20 +718,28 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
|
|
||||||
class ChannelsDictionary(utils.IterableMap):
|
class ChannelsDictionary(utils.IterableMap):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.noFlush = False
|
||||||
self.filename = None
|
self.filename = None
|
||||||
self.channels = ircutils.IrcDict()
|
self.channels = ircutils.IrcDict()
|
||||||
|
|
||||||
def open(self, filename):
|
def open(self, filename):
|
||||||
|
self.noFlush = True
|
||||||
|
try:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
reader = unpreserve.Reader(IrcChannelCreator, self)
|
reader = unpreserve.Reader(IrcChannelCreator, self)
|
||||||
try:
|
try:
|
||||||
reader.readFile(filename)
|
reader.readFile(filename)
|
||||||
|
self.noFlush = False
|
||||||
|
self.flush()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.error('Invalid channel database, starting from scratch.')
|
log.error('Invalid channel database, resetting to empty.')
|
||||||
log.error('Exact error: %s', utils.exnToString(e))
|
log.error('Exact error: %s', utils.exnToString(e))
|
||||||
|
finally:
|
||||||
|
self.noFlush = False
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Flushes the channel database to its file."""
|
"""Flushes the channel database to its file."""
|
||||||
|
if not self.noFlush:
|
||||||
if self.filename is not None:
|
if self.filename is not None:
|
||||||
fd = utils.transactionalFile(self.filename)
|
fd = utils.transactionalFile(self.filename)
|
||||||
for (channel, c) in self.channels.iteritems():
|
for (channel, c) in self.channels.iteritems():
|
||||||
|
Loading…
Reference in New Issue
Block a user