libtorrent icon indicating copy to clipboard operation
libtorrent copied to clipboard

Relative path for .torrent file is not supported (Windows)

Open blackyblack opened this issue 10 months ago • 6 comments

When trying to create torrent_info from .torrent file using relative path, i.e. ../alice.torrent, libtorrent responds with error with some shady description: Invalid argument [generic 22] It seems only Windows is affected, because bug is in canonicalization code.

blackyblack avatar Feb 28 '25 15:02 blackyblack

.. and . folders do not exist on windows. And it is ..\alice.torrent for windows.

I do not get it? What is ../alice.torrent, is that some file inside some other .torrent file?

ValeZAA avatar Apr 12 '25 13:04 ValeZAA

No, it's path to torrent file.

blackyblack avatar Apr 12 '25 20:04 blackyblack

libtorrent uses UNC paths on windows. This is the only way to lift file name length restrictions as well as some other restrictions. As a security feature, windows does not allow relative paths or absolute paths that include ...

It's actually a pretty reasonable stance I think. Instead of relying on a global variable (the current working directory), you should resolve your relative path to an absolute one. The risks of relying on the current working directory is that any part of the program can change it at any time.

arvidn avatar Apr 28 '25 01:04 arvidn

Relative directories are more reliable, I think. You can isolate your working directory and move it anywhere without reconfiguration. .. path might have security issues indeed but it's up to system administrator, not for the library to decide what's the best. As for UNC, you could allow both options. Legacy paths for inter system compatibility and UNC for additional Windows features.

blackyblack avatar Apr 28 '25 07:04 blackyblack

can isolate your working directory and move it anywhere without reconfiguration.

Not on windows. Regedit declares absolute paths for % % and even on Linux ld needs to be present in some specific place and there are requirements for usr sbin lib folders. Also why would you want to do it if you can hard link and move to a different drive, on Windows stuff is always mounted so you can do it even on a different drive.

Finally I use Windows terminal and almost always use absolute paths, unless the app requires THAT its shared LIBRARIES be in ./ when executed.

ValeZAA avatar Apr 28 '25 09:04 ValeZAA

Not sure how regedit or ld are relevant here. We are talking about where to take user's torrent file and it is completely different from system specific paths.

if you can hard link and move to a different drive

It is unusual to do so for average Windows user. Much easier is to put .torrent file aside with .exe and run.

Finally I use Windows terminal and almost always use absolute paths

Well it's not everyone's typical behavior. I don't think it's a good idea to force people to use absolute paths without really good reason.

blackyblack avatar Apr 28 '25 09:04 blackyblack