From 38a3ba277c5ccb6f58a43dd272bd2ed9a728566a Mon Sep 17 00:00:00 2001 From: TheAMM Date: Sat, 13 May 2017 02:34:55 +0300 Subject: [PATCH] Make sure torrent backup directory exists before writing torrent --- .gitignore | 1 + nyaa/routes.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8fab61d..c329f4c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ install/* uwsgi.sock /test_torrent_batch config.py +torrents diff --git a/nyaa/routes.py b/nyaa/routes.py index 3325a43..5af9bfa 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -599,10 +599,16 @@ def upload(): db.session.commit() + # Store the actual torrent file as well torrent_file = form.torrent_file.data if app.config.get('BACKUP_TORRENT_FOLDER'): torrent_file.seek(0, 0) - torrent_path = os.path.join(app.config['BACKUP_TORRENT_FOLDER'], '{}.{}'.format(torrent.id, secure_filename(torrent_file.filename))) + + torrent_dir = app.config['BACKUP_TORRENT_FOLDER'] + if not os.path.exists(torrent_dir): + os.makedirs(torrent_dir) + + torrent_path = os.path.join(torrent_dir, '{}.{}'.format(torrent.id, secure_filename(torrent_file.filename))) torrent_file.save(torrent_path) torrent_file.close()