|
2 | 2 | #
|
3 | 3 | # SPDX-License-Identifier: AGPL-3.0-only
|
4 | 4 |
|
| 5 | +import platform |
5 | 6 | from collections.abc import Callable, Iterator
|
6 | 7 | from dataclasses import dataclass
|
7 | 8 | from datetime import date
|
@@ -334,13 +335,24 @@ def main() -> str:
|
334 | 335 | @register_admin_link("Download DB", right=True)
|
335 | 336 | @bp.route("/get_db")
|
336 | 337 | def get_db_file() -> Response:
|
337 |
| - db_backup_file = NamedTemporaryFile(delete_on_close=False) |
338 |
| - db_backup_file.close() # avoid double-open in the backup_db function (fails on Windows) |
339 |
| - backup_db(Path(db_backup_file.name)) |
340 | 338 | db_name = current_app.config['DATABASE_NAME']
|
341 | 339 | db_basename = Path(db_name).stem
|
342 | 340 | dl_name = f"{db_basename}_{date.today().strftime('%Y%m%d')}.db"
|
343 |
| - return send_file(db_backup_file.name, mimetype='application/vnd.sqlite3', as_attachment=True, download_name=dl_name) |
| 341 | + |
| 342 | + if platform.system() == "Windows": |
| 343 | + # Slightly unsafe way to do it, because the file may be written while |
| 344 | + # send_file is sending it. Temp file issues make it hard to do |
| 345 | + # otherwise on Windows, though, and no one should run a production |
| 346 | + # server for this on Windows, anyway. |
| 347 | + return send_file(current_app.config['DATABASE'], |
| 348 | + mimetype='application/vnd.sqlite3', |
| 349 | + as_attachment=True, download_name=dl_name) |
| 350 | + else: |
| 351 | + db_backup_file = NamedTemporaryFile() |
| 352 | + backup_db(Path(db_backup_file.name)) |
| 353 | + return send_file(db_backup_file, |
| 354 | + mimetype='application/vnd.sqlite3', |
| 355 | + as_attachment=True, download_name=dl_name) |
344 | 356 |
|
345 | 357 |
|
346 | 358 | @bp.route("/consumer/new")
|
|
0 commit comments