Warn user when database is corrupted and unreadable. Fixes #3761
This commit is contained in:
parent
2e7d8f7486
commit
0d427eff3b
|
@ -37,6 +37,7 @@ import re
|
||||||
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common import helpers
|
from common import helpers
|
||||||
|
from common import exceptions
|
||||||
from message_control import MessageControl
|
from message_control import MessageControl
|
||||||
from conversation_textview import ConversationTextview
|
from conversation_textview import ConversationTextview
|
||||||
from message_textview import MessageTextView
|
from message_textview import MessageTextView
|
||||||
|
@ -2004,8 +2005,13 @@ class ChatControl(ChatControlBase):
|
||||||
pending_how_many += len(gajim.events.get_events(self.account,
|
pending_how_many += len(gajim.events.get_events(self.account,
|
||||||
self.contact.get_full_jid(), ['chat', 'pm']))
|
self.contact.get_full_jid(), ['chat', 'pm']))
|
||||||
|
|
||||||
|
try:
|
||||||
rows = gajim.logger.get_last_conversation_lines(jid, restore_how_many,
|
rows = gajim.logger.get_last_conversation_lines(jid, restore_how_many,
|
||||||
pending_how_many, timeout, self.account)
|
pending_how_many, timeout, self.account)
|
||||||
|
except exceptions.DatabaseMalformed:
|
||||||
|
dialogs.ErrorDialog(_('Database Error'),
|
||||||
|
_('The database file (%s) cannot be read. Try to repare it or remove it (all history will be lost).') % common.logger.LOG_DB_PATH)
|
||||||
|
rows = []
|
||||||
local_old_kind = None
|
local_old_kind = None
|
||||||
for row in rows: # row[0] time, row[1] has kind, row[2] the message
|
for row in rows: # row[0] time, row[1] has kind, row[2] the message
|
||||||
if not row[2]: # message is empty, we don't print it
|
if not row[2]: # message is empty, we don't print it
|
||||||
|
|
|
@ -35,6 +35,14 @@ class PysqliteOperationalError(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
class DatabaseMalformed(Exception):
|
||||||
|
'''The databas can't be read'''
|
||||||
|
def __init__(self):
|
||||||
|
Exception.__init__(self)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return _('Database cannot be read.')
|
||||||
|
|
||||||
class ServiceNotAvailable(Exception):
|
class ServiceNotAvailable(Exception):
|
||||||
'''This exception is raised when we cannot use Gajim remotely'''
|
'''This exception is raised when we cannot use Gajim remotely'''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -136,8 +136,11 @@ class Logger:
|
||||||
self.get_jids_already_in_db()
|
self.get_jids_already_in_db()
|
||||||
|
|
||||||
def get_jids_already_in_db(self):
|
def get_jids_already_in_db(self):
|
||||||
|
try:
|
||||||
self.cur.execute('SELECT jid FROM jids')
|
self.cur.execute('SELECT jid FROM jids')
|
||||||
rows = self.cur.fetchall() # list of tupples: [(u'aaa@bbb',), (u'cc@dd',)]
|
rows = self.cur.fetchall() # list of tupples: [(u'aaa@bbb',), (u'cc@dd',)]
|
||||||
|
except sqlite.DatabaseError:
|
||||||
|
raise exceptions.DatabaseMalformed
|
||||||
self.jids_already_in = []
|
self.jids_already_in = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
# row[0] is first item of row (the only result here, the jid)
|
# row[0] is first item of row (the only result here, the jid)
|
||||||
|
@ -443,6 +446,7 @@ class Logger:
|
||||||
timed_out = now - (timeout * 60) # before that they are too old
|
timed_out = now - (timeout * 60) # before that they are too old
|
||||||
# so if we ask last 5 lines and we have 2 pending we get
|
# so if we ask last 5 lines and we have 2 pending we get
|
||||||
# 3 - 8 (we avoid the last 2 lines but we still return 5 asked)
|
# 3 - 8 (we avoid the last 2 lines but we still return 5 asked)
|
||||||
|
try:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
SELECT time, kind, message FROM logs
|
SELECT time, kind, message FROM logs
|
||||||
WHERE (%s) AND kind IN (%d, %d, %d, %d, %d) AND time > %d
|
WHERE (%s) AND kind IN (%d, %d, %d, %d, %d) AND time > %d
|
||||||
|
@ -454,6 +458,8 @@ class Logger:
|
||||||
)
|
)
|
||||||
|
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
|
except sqlite.DatabaseError:
|
||||||
|
raise exceptions.DatabaseMalformed
|
||||||
results.reverse()
|
results.reverse()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
22
src/gajim.py
22
src/gajim.py
|
@ -145,15 +145,15 @@ except Warning, msg:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
warnings.resetwarnings()
|
warnings.resetwarnings()
|
||||||
|
|
||||||
import message_control
|
pritext = ''
|
||||||
|
|
||||||
from chat_control import ChatControlBase
|
|
||||||
from atom_window import AtomWindow
|
|
||||||
|
|
||||||
import negotiation
|
|
||||||
|
|
||||||
from common import exceptions
|
from common import exceptions
|
||||||
from common.zeroconf import connection_zeroconf
|
try:
|
||||||
|
from common import gajim
|
||||||
|
except exceptions.DatabaseMalformed:
|
||||||
|
pritext = _('Database Error')
|
||||||
|
sectext = _('The database file (%s) cannot be read. Try to repare it or remove it (all history will be lost).') % common.logger.LOG_DB_PATH
|
||||||
|
else:
|
||||||
from common import dbus_support
|
from common import dbus_support
|
||||||
if dbus_support.supported:
|
if dbus_support.supported:
|
||||||
import dbus
|
import dbus
|
||||||
|
@ -166,7 +166,6 @@ if os.name == 'posix': # dl module is Unix Only
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pritext = ''
|
|
||||||
if gtk.pygtk_version < (2, 8, 0):
|
if gtk.pygtk_version < (2, 8, 0):
|
||||||
pritext = _('Gajim needs PyGTK 2.8 or above')
|
pritext = _('Gajim needs PyGTK 2.8 or above')
|
||||||
sectext = _('Gajim needs PyGTK 2.8 or above to run. Quiting...')
|
sectext = _('Gajim needs PyGTK 2.8 or above to run. Quiting...')
|
||||||
|
@ -230,14 +229,19 @@ import math
|
||||||
|
|
||||||
import gtkgui_helpers
|
import gtkgui_helpers
|
||||||
import notify
|
import notify
|
||||||
|
import message_control
|
||||||
|
import negotiation
|
||||||
|
|
||||||
|
from chat_control import ChatControlBase
|
||||||
|
from atom_window import AtomWindow
|
||||||
|
|
||||||
import common.sleepy
|
import common.sleepy
|
||||||
|
|
||||||
from common.xmpp import idlequeue
|
from common.xmpp import idlequeue
|
||||||
|
from common.zeroconf import connection_zeroconf
|
||||||
from common import nslookup
|
from common import nslookup
|
||||||
from common import proxy65_manager
|
from common import proxy65_manager
|
||||||
from common import socks5
|
from common import socks5
|
||||||
from common import gajim
|
|
||||||
from common import helpers
|
from common import helpers
|
||||||
from common import optparser
|
from common import optparser
|
||||||
from common import dataforms
|
from common import dataforms
|
||||||
|
|
Loading…
Reference in New Issue