Merge branch 'master' of github.com:beetbox/beets

This commit is contained in:
Adrian Sampson 2017-04-19 11:37:36 -04:00
commit 18127ce6bf
3 changed files with 31 additions and 2 deletions

View file

@ -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."""

View file

@ -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)

View file

@ -90,6 +90,8 @@ Fixes:
made each disc be imported separately in different releases. :bug:`2493`
* Invalid date queries now print an error message instead of being silently
ignored. Thanks to :user:`discopatrick`. :bug:`2513` :bug:`2517`
* 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)