make sqlite open errors clearer
Gitea/pysonic/pipeline/head This commit looks good Details
Gitea/pysonic/pipeline/pr-master This commit looks good Details

if filesystem permissions on the directory the sqlite database database file is in are such that the app cannot list or create files, sqlite gives a vague error:

```
sqlite3.OperationalError: unable to open database file
```

whereas python's open() will give a better hint ("permission denied"). So, we try opening the database file with python first.

also, add chmods to the startup scripts to avoid this issue in the future
This commit is contained in:
dave 2022-12-24 13:48:37 -08:00
parent f0b9074391
commit e5158cfdc7
2 changed files with 9 additions and 5 deletions

View File

@ -10,7 +10,7 @@ from collections import Iterable
from pysonic.scanner import PysonicFilesystemScanner
logging = logging.getLogger("database")
logger = logging.getLogger("database")
LETTER_GROUPS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
@ -63,7 +63,8 @@ class PysonicDatabase(object):
self.scanner = PysonicFilesystemScanner(self)
def open(self):
logging.debug("opening database: %s", self.path)
with open(self.path, "rb"): # sqlite doesn't give very descriptive permission errors, but this does
pass
self.db = sqlite3.connect(self.path, **self.sqlite_opts)
self.db.row_factory = dict_factory
@ -159,14 +160,14 @@ class PysonicDatabase(object):
# Initialize DB
if len(c.fetchall()) == 0:
logging.warning("Initializing database")
logger.warning("Initializing database")
for query in queries:
c.execute(query)
c.execute("COMMIT")
else:
# Migrate if old db exists
# c.execute("""UPDATE meta SET value=? WHERE key="db_version";""", (str(version), ))
# logging.warning("db schema is version {}".format(version))
# logger.warning("db schema is version {}".format(version))
pass
def get_artist_info(self, item_id):

View File

@ -1,5 +1,8 @@
#!/bin/bash
chown -R app:app /db/
set -x
chmod 755 /db/.
chown -R app:app /db
exec sudo --preserve-env -Hu app pysonicd $@