1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 15:19:59 +00:00

Delete cached torrent file when replacing torrent.

This commit is contained in:
nyaadev 2017-08-07 00:20:02 +02:00
parent 602d35bab7
commit 1c3724cae1

View file

@ -51,6 +51,7 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False):
if torrent_data.db_id is not None: if torrent_data.db_id is not None:
models.Torrent.query.filter_by(id=torrent_data.db_id).delete() models.Torrent.query.filter_by(id=torrent_data.db_id).delete()
db.session.commit() db.session.commit()
_delete_cached_torrent_file(torrent_data.db_id)
# The torrent has been validated and is safe to access with ['foo'] etc - all relevant # The torrent has been validated and is safe to access with ['foo'] etc - all relevant
# keys and values have been checked for (see UploadForm in forms.py for details) # keys and values have been checked for (see UploadForm in forms.py for details)
@ -235,3 +236,11 @@ def tracker_api(info_hashes, method):
return False return False
return req.status == 200 return req.status == 200
def _delete_cached_torrent_file(torrent_id):
# Note: obviously temporary
cached_torrent = os.path.join(app.config['BASE_DIR'],
'torrent_cache', str(torrent_id) + '.torrent')
if os.path.exists(cached_torrent):
os.remove(cached_torrent)