Renaming a file overwrites the existing file
Renaming a file using torrent_handle::rename_file() overwrites the existing file which is hardly desirable behavior. It should fail instead.
I believe this happens when the file being renamed has not been created yet (because nothing has been downloaded to it). This case is currently treated the same as adding a torrent where some files may already exist on disk, except, the new file won't be checked for data matching the torrent. It will just be overwritten.
Perhaps a better solution would be to always fail when creating a file for the first time (during download) if it already exists. Failing if the target file already exists when renaming would be an optimization of that, failing earlier.
oh, it also happens because if rename() fails, we fall back to copy()
Perhaps a better solution would be to always fail when creating a file for the first time (during download) if it already exists. Failing if the target file already exists when renaming would be an optimization of that, failing earlier.
👍
oh, it also happens because if
rename()fails, we fall back tocopy()
Yes. But even rename() doesn't guarantee that it fails if target file exists. `std::rename() describes its behavior if target file exists as implementation-defined.
https://github.com/arvidn/libtorrent/pull/8028