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()
|
initialize_file_icon_provider()
|
||||||
try:
|
try:
|
||||||
main = Main()
|
main = Main()
|
||||||
except DatabaseLocked:
|
except DatabaseLocked, err:
|
||||||
QMessageBox.critical(None, 'Cannot Start '+__appname__,
|
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
|
return 1
|
||||||
sys.excepthook = main.unhandled_exception
|
sys.excepthook = main.unhandled_exception
|
||||||
return app.exec_()
|
return app.exec_()
|
||||||
|
@ -42,33 +42,38 @@ class Concatenate(object):
|
|||||||
|
|
||||||
_lock_file = None
|
_lock_file = None
|
||||||
class DatabaseLocked(Exception):
|
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):
|
def _lock(path):
|
||||||
path = os.path.join(os.path.dirname(path), '.'+os.path.basename(path)+'.lock')
|
path = os.path.join(os.path.dirname(path), '.'+os.path.basename(path)+'.lock')
|
||||||
global _lock_file
|
global _lock_file
|
||||||
if _lock_file is not None:
|
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:
|
try:
|
||||||
_lock_file = open(path, 'wb')
|
_lock_file = open(path, 'wb')
|
||||||
except IOError:
|
except IOError:
|
||||||
raise DatabaseLocked('Database in use by another instance')
|
raise DatabaseLocked('Database in use by another instance', _lock_file.name)
|
||||||
try:
|
try:
|
||||||
import fcntl, errno
|
import fcntl, errno
|
||||||
try:
|
try:
|
||||||
fcntl.lockf(_lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
fcntl.lockf(_lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||||
except IOError, err:
|
except IOError, err:
|
||||||
|
path = _lock_file.name
|
||||||
_lock_file = None
|
_lock_file = None
|
||||||
if err.errno in (errno.EACCES, errno.EAGAIN):
|
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:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
import msvcrt
|
import msvcrt
|
||||||
try:
|
try:
|
||||||
msvcrt.locking(_lock_file.fileno(), msvcrt.LK_NBLCK, 1)
|
msvcrt.locking(_lock_file.fileno(), msvcrt.LK_NBLCK, 1)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
path = _lock_file.name
|
||||||
_lock_file = None
|
_lock_file = None
|
||||||
raise DatabaseLocked('Database in use by another instance')
|
raise DatabaseLocked('Database in use by another instance', path)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user