Skip to content

Commit 7cdebe5

Browse files
committed
Log warning if db file doesn't seem writable
1 parent dd81640 commit 7cdebe5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mautrix/util/async_db/aiosqlite.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from contextlib import asynccontextmanager
1010
import asyncio
1111
import logging
12+
import os
1213
import re
1314
import sqlite3
1415

@@ -148,6 +149,11 @@ async def start(self) -> None:
148149
raise RuntimeError("database pool can't be restarted")
149150
self.log.debug(f"Connecting to {self.url}")
150151
self.log.debug(f"Database connection init commands: {self._init_commands}")
152+
if os.path.exists(self._path):
153+
if not os.access(self._path, os.W_OK):
154+
self.log.warning("Database file doesn't seem writable")
155+
elif not os.access(os.path.dirname(os.path.abspath(self._path)), os.W_OK):
156+
self.log.warning("Database file doesn't exist and directory doesn't seem writable")
151157
for _ in range(self._pool.maxsize):
152158
conn = await TxnConnection(self._path, **self._db_args)
153159
if self._init_commands:

0 commit comments

Comments
 (0)