From b04347fcb1e218b4c4b2949adb5afdbc8517d7b4 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Fri, 8 Nov 2024 15:20:03 -0600 Subject: [PATCH] Minor cleanup of backup_db(). --- src/gened/admin.py | 2 +- src/gened/db.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gened/admin.py b/src/gened/admin.py index d72bbd2..b9b40af 100644 --- a/src/gened/admin.py +++ b/src/gened/admin.py @@ -335,7 +335,7 @@ def main() -> str: @bp.route("/get_db") def get_db_file() -> Response: db_backup_file = NamedTemporaryFile() - backup_db(db_backup_file.name) + backup_db(Path(db_backup_file.name)) db_name = current_app.config['DATABASE_NAME'] db_basename = Path(db_name).stem dl_name = f"{db_basename}_{date.today().strftime('%Y%m%d')}.db" diff --git a/src/gened/db.py b/src/gened/db.py index 2e2618d..8c31256 100644 --- a/src/gened/db.py +++ b/src/gened/db.py @@ -57,13 +57,12 @@ def get_db() -> sqlite3.Connection: return g.db -def backup_db(target: str | Path) -> None: +def backup_db(target: Path) -> None: """ Safely make a backup of the database to the given path. - target: str or any path-like object. Must not exist yet or be empty. + target: Path object to the location of the new backup. Must not exist yet or be empty. """ - target = Path(target) if target.exists() and target.stat().st_size > 0: - raise FileExistsError(errno.EEXIST, "File already exists or is not empty", target) + raise FileExistsError(errno.EEXIST, "File already exists and is not empty", target) db = get_db() tmp_db = sqlite3.connect(target)