From 1c3724cae15623aa9d5d581a4b73f202629dfdbc Mon Sep 17 00:00:00 2001 From: nyaadev Date: Mon, 7 Aug 2017 00:20:02 +0200 Subject: [PATCH] Delete cached torrent file when replacing torrent. --- nyaa/backend.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nyaa/backend.py b/nyaa/backend.py index 2b8c1f8..5b56a52 100644 --- a/nyaa/backend.py +++ b/nyaa/backend.py @@ -51,6 +51,7 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False): if torrent_data.db_id is not None: models.Torrent.query.filter_by(id=torrent_data.db_id).delete() 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 # 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 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)