Discussion:
[libtorrent] re-add the same torrent
Alexander Dyagilev
2017-07-07 12:13:16 UTC
Permalink
Hello,

I need to delete a torrent and add it again.

Docs states:

/"The removal of the torrent is asynchronous, there is no guarantee that
adding the same torrent immediately after it was removed will not throw
a //libtorrent_exception
<http://libtorrent.org/reference-Error_Codes.html#libtorrent_exception>//exception."/

Is it enough to wait for /torrent_removed_alert/ and then add the
torrent immediately, or should wait for /torrent_deleted_alert/ also (in
case I delete a torrent with the files)?
Arvid Norberg
2017-07-14 05:12:38 UTC
Permalink
Post by Alexander Dyagilev
Hello,
I need to delete a torrent and add it again.
/"The removal of the torrent is asynchronous, there is no guarantee that
adding the same torrent immediately after it was removed will not throw a
//libtorrent_exception <http://libtorrent.org/referen
ce-Error_Codes.html#libtorrent_exception>//exception."/
Is it enough to wait for /torrent_removed_alert/ and then add the torrent
immediately, or should wait for /torrent_deleted_alert/ also (in case I
delete a torrent with the files)?
Waiting for torrent_removed_alert should be sufficient. Note though that if
you're actually deleting the files, and you add the new torrent with the
same download directory, there may still be a risk of a race condition
where the files are being removed as the new torrent is looking at them.

But adding the new torrent with the expectation of picking up the old
files, or with a different save_path should not be a problem. In fact,
looking at this now, I don't see how it could be a problem to remove a
torrent and then re-add it back-to-back. The main thread serializes
handling of all calls into the session, so the torrent will have been
removed by the time the next call is handled.
--
Arvid Norberg
Loading...