mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
More helpful error message when the database is locked
This commit is contained in:
parent
90d0ed2136
commit
8f9bb12c7f
@ -801,9 +801,9 @@ def main(args=sys.argv):
|
||||
initialize_file_icon_provider()
|
||||
try:
|
||||
main = Main()
|
||||
except DatabaseLocked:
|
||||
except DatabaseLocked, err:
|
||||
QMessageBox.critical(None, 'Cannot Start '+__appname__,
|
||||
'Another program is using the database. Perhaps %s is already running?'%(__appname__,))
|
||||
'<p>Another program is using the database. <br/>Perhaps %s is already running?<br/>If not try deleting the file %s'%(__appname__, err.lock_file_path))
|
||||
return 1
|
||||
sys.excepthook = main.unhandled_exception
|
||||
return app.exec_()
|
||||
|
@ -42,33 +42,38 @@ class Concatenate(object):
|
||||
|
||||
_lock_file = None
|
||||
class DatabaseLocked(Exception):
|
||||
pass
|
||||
|
||||
def __init__(self, msg, lock_file_path):
|
||||
Exception.__init__(self, msg)
|
||||
self.lock_file_path = lock_file_path
|
||||
|
||||
def _lock(path):
|
||||
path = os.path.join(os.path.dirname(path), '.'+os.path.basename(path)+'.lock')
|
||||
global _lock_file
|
||||
if _lock_file is not None:
|
||||
raise DatabaseLocked('Database already locked in this instance.')
|
||||
raise DatabaseLocked('Database already locked in this instance.', _lock_file.name)
|
||||
try:
|
||||
_lock_file = open(path, 'wb')
|
||||
except IOError:
|
||||
raise DatabaseLocked('Database in use by another instance')
|
||||
raise DatabaseLocked('Database in use by another instance', _lock_file.name)
|
||||
try:
|
||||
import fcntl, errno
|
||||
try:
|
||||
fcntl.lockf(_lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||
except IOError, err:
|
||||
path = _lock_file.name
|
||||
_lock_file = None
|
||||
if err.errno in (errno.EACCES, errno.EAGAIN):
|
||||
raise DatabaseLocked('Database in use by another instance')
|
||||
raise DatabaseLocked('Database in use by another instance', path)
|
||||
except ImportError:
|
||||
try:
|
||||
import msvcrt
|
||||
try:
|
||||
msvcrt.locking(_lock_file.fileno(), msvcrt.LK_NBLCK, 1)
|
||||
except IOError:
|
||||
path = _lock_file.name
|
||||
_lock_file = None
|
||||
raise DatabaseLocked('Database in use by another instance')
|
||||
raise DatabaseLocked('Database in use by another instance', path)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user