From 404af22bf71056009ae34518d67939da279bf922 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 21 Mar 2023 17:38:10 -0700 Subject: [PATCH 1/3] check if specified sqlite databse is a file, if it isn't throw an error and exit --- synapse/_scripts/synapse_port_db.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/synapse/_scripts/synapse_port_db.py b/synapse/_scripts/synapse_port_db.py index 78d76d38ad90..b2c2b1f6bba3 100755 --- a/synapse/_scripts/synapse_port_db.py +++ b/synapse/_scripts/synapse_port_db.py @@ -18,6 +18,7 @@ import argparse import curses import logging +import os import sys import time import traceback @@ -1326,6 +1327,11 @@ def main() -> None: filename="port-synapse.log" if args.curses else None, ) + if not os.path.isfile(args.sqlite_database): + sys.stderr.write("The sqlite database you specified does not exist, please check that you have the" \ + "correct path.") + sys.exit(1) + sqlite_config = { "name": "sqlite3", "args": { From db62d92944ef5eab57f5acda4066af52d5a18406 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 21 Mar 2023 17:46:23 -0700 Subject: [PATCH 2/3] add a check to determine that sqlite db exists before trying to port from it --- synapse/_scripts/synapse_port_db.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/synapse/_scripts/synapse_port_db.py b/synapse/_scripts/synapse_port_db.py index b2c2b1f6bba3..94b86c1d6ff5 100755 --- a/synapse/_scripts/synapse_port_db.py +++ b/synapse/_scripts/synapse_port_db.py @@ -1328,8 +1328,10 @@ def main() -> None: ) if not os.path.isfile(args.sqlite_database): - sys.stderr.write("The sqlite database you specified does not exist, please check that you have the" \ - "correct path.") + sys.stderr.write( + "The sqlite database you specified does not exist, please check that you have the" + "correct path." + ) sys.exit(1) sqlite_config = { From 422dec0966e01fde10845658dd0440a3d99c689c Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 21 Mar 2023 17:46:29 -0700 Subject: [PATCH 3/3] newsfragment --- changelog.d/15306.bugfix | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/15306.bugfix diff --git a/changelog.d/15306.bugfix b/changelog.d/15306.bugfix new file mode 100644 index 000000000000..f5eb716f12c5 --- /dev/null +++ b/changelog.d/15306.bugfix @@ -0,0 +1,2 @@ +Add a check to [SQLite port_db script](https://matrix-org.github.io/synapse/latest/postgres.html#porting-from-sqlite) +to ensure that the sqlite database passed to the script exists before trying to port from it.