mirror of
https://github.com/beetbox/beets.git
synced 2025-12-10 18:43:02 +01:00
Merge pull request #2508 from Mary011196/master
OperationalError from SQlite that indicates a permissions problem.
This commit is contained in:
commit
21c59bfcdd
3 changed files with 31 additions and 2 deletions
|
|
@ -33,6 +33,15 @@ from .query import MatchQuery, NullSort, TrueQuery
|
|||
import six
|
||||
|
||||
|
||||
class DBAccessError(Exception):
|
||||
"""The SQLite database became inaccessible.
|
||||
|
||||
This can happen when trying to read or write the database when, for
|
||||
example, the database file is deleted or otherwise disappears. There
|
||||
is probably no way to recover from this error.
|
||||
"""
|
||||
|
||||
|
||||
class FormattedMapping(collections.Mapping):
|
||||
"""A `dict`-like formatted view of a model.
|
||||
|
||||
|
|
@ -680,8 +689,18 @@ class Transaction(object):
|
|||
"""Execute an SQL statement with substitution values and return
|
||||
the row ID of the last affected row.
|
||||
"""
|
||||
cursor = self.db._connection().execute(statement, subvals)
|
||||
return cursor.lastrowid
|
||||
try:
|
||||
cursor = self.db._connection().execute(statement, subvals)
|
||||
return cursor.lastrowid
|
||||
except sqlite3.OperationalError as e:
|
||||
# In two specific cases, SQLite reports an error while accessing
|
||||
# the underlying database file. We surface these exceptions as
|
||||
# DBAccessError so the application can abort.
|
||||
if e.args[0] in ("attempt to write a readonly database",
|
||||
"unable to open database file"):
|
||||
raise DBAccessError(e.args[0])
|
||||
else:
|
||||
raise
|
||||
|
||||
def script(self, statements):
|
||||
"""Execute a string containing multiple SQL statements."""
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ from beets import config
|
|||
from beets.util import confit, as_string
|
||||
from beets.autotag import mb
|
||||
from beets.dbcore import query as db_query
|
||||
from beets.dbcore import db
|
||||
import six
|
||||
|
||||
# On Windows platforms, use colorama to support "ANSI" terminal colors.
|
||||
|
|
@ -1253,3 +1254,10 @@ def main(args=None):
|
|||
except KeyboardInterrupt:
|
||||
# Silently ignore ^C except in verbose mode.
|
||||
log.debug(u'{}', traceback.format_exc())
|
||||
except db.DBAccessError as exc:
|
||||
log.error(
|
||||
u'database access error: {0}\n'
|
||||
u'the library file might have a permissions problem',
|
||||
exc
|
||||
)
|
||||
sys.exit(1)
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ Fixes:
|
|||
AAC codec instead of faac. Thanks to :user:`jansol`. :bug:`2484`
|
||||
* Fix import of multidisc releases with subdirectories, which previously
|
||||
made each disc be imported separately in different releases. :bug:`2493`
|
||||
* When the SQLite database stops being accessible, we now print a friendly
|
||||
error message. Thanks to :user:`Mary011196`. :bug:`1676` :bug:`2508`
|
||||
|
||||
|
||||
1.4.3 (January 9, 2017)
|
||||
|
|
|
|||
Loading…
Reference in a new issue