Make sure torrent backup directory exists before writing torrent

This commit is contained in:
TheAMM 2017-05-13 02:34:55 +03:00
parent 39230e1f39
commit 38a3ba277c
2 changed files with 8 additions and 1 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ install/*
uwsgi.sock
/test_torrent_batch
config.py
torrents

View File

@ -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()