-
-
Notifications
You must be signed in to change notification settings - Fork 985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MacOS] Downloading a torrent with symbolic links in it and libtorrent do not create them #3636
Comments
At a guess (I don't know if this is the real reason).. symlinks can be a security hazard to users, and they can add very unexpected behaviour for users. So if it were easy to do this, I think people probably wouldn't do it, anyway. The bigger problem is that symlinks are not actually "files" with data in them. Symlinks are a feature of the file system they're made on, and I don't think there's any specified way to represent them in torrent files. As a Mac user, when you make a symlink, it's not the same as when I, a Linux user, make a symlink. The results look similar, but the reality is that there is no file to include. Now, if you meant "I'd like libtorrent to include a file, as a normal file, when I link it into a folder".. at least on Linux, you could probably do that with a Hard Symlink, and Mac might have an equivalent to that? The result would be that, to Libtorrent, it would be seeing the full file everywhere that a "link" appeared. So if there were 10 links to the same file, it would hash the file ten times. And users would download the file again, ten times. And, unless the files aligned on piece boundaries perfectly, the pieces would also be different for all 10 copies. :) |
As i can see in libtorrent documentation, it supports storing symlinks in torrent-files (there are special flags and fields in torrent_info class). So if it allows storing symlinks, i guess it must restoring it too, in other case what is the reason of it?.. |
looking through the code, I can only find support for creating and loading/parsing torrents with symlinks, not to actually create the symlinks. I think a good place to do so would be in @AlexanderVitiuk would you be up for writing a test demonstrating this failing? (and I can implement support for it). I think extending |
Ok i will try, thanks for answer) |
Finally i got free time to do it. Attached test.zip contains 2 files: |
thanks! I'll make some tweaks to not actually download anything as part of the test. btw, did libtorrent actually create that torrent? I would be a bit surprised, since the name of the torrent had quotes in it. Perhaps the windows shell doesn't strip quotes. |
I used compiled example tool "make_torrent" to create it (on macosx). It called from python script: |
I see. so you added the quotes yourself. anyway, please give this patch a try! It's against |
@AlexanderVitiuk have you had a chance to try this out? |
No, sorry, i hope i will try today or tomorrow. |
Checked on test torrent with symlinks, seem it is still not working (still create zero-sized files instead of symlinks). |
did you try running |
symlinks_restore test passed, but for some reason if i use compiled library libtorrent.a in my c++ project and downloading data of symlink2.torrent, it makes zero-sized files instead of symlinks... |
make sure you rebuild everything that needs rebuilding and that you're linking against the new build of the library |
is there a chance you may be picking up an "installed" copy of libtorrent? |
Finally i figured out what happened: |
Maybe it is off top, but i have question: is it possible to get sha1 piece hashes from create_torrent class after lt::set_piece_hashes(...), to use them for calculate file hashes for create_torrent.set_file_hash(...)? |
you cannot calculate file hashes from the piece hashes. The feature to calculate file hashes and piece hashes in a single pass got quite complicated when making the disk I/O threaded, that's why I removed it (as it seemed like a less useful feature than better disk performance). I'm afraid you'll have to calculate file hashes by hand. Alternatively, you can try out the |
There's actually some more important things that need fixing for this patch. There currently aren't any checks to make sure symlink targets are files from within the torrent. Also, symlinks are not relative to the torrent root right now, as specified in the BEP. |
It seems now symlinks can be created before target object is downloaded. In this case, if terminate downloading process and shutdown session just after symlink created, and then start session again from checking/downloading, it is failed when tried to create this symlink again. Got such alerts: SDL2.framework/Resources - symlink to folder inside ....../SDL2.framework/ which is not downloaded yet. |
@AlexanderVitiuk could you please test this patch? #3709 It attempts to fix the issue you mention, where the symbolic link already exists. However, perhaps more importantly, it also validates the symlink targets in the torrent file and adds some stricter requirements on them. The BEP47 requires link targets paths to be rooted in torrent root. I allow relative paths for backwards compatibility for now. |
Downloaded/built branch libtorrent-symlink-fixes. Maybe it is important:
|
Could you try downloading it fresh? That error suggests that the symlink exists, but has a different target than what's trying to be written to it. With this patch, all targets are relative to the link itself, previously the symlink target was not validated by just written verbatim. This also means that symlink targets must point to another file in the torrent right now (or to a directory). If it doesn't, the symlink is made to point to itself. If this happens, it's possible the existing symlink also mismatches the one trying to be created. |
I downloaded to fresh folder, but used old .torrent file. |
does a newly built |
It seems newly build dump_torrent shows it correct: |
do you get the error you mentioned when downloading to a fresh (empty) download directory? |
Yes, this error when downloading into fresh empty folder. |
thanks, fixed! Please try again |
Now it is do not create any symlink when downloading... Also got 1 new warning during library compilation: |
ok, third time's the charm! I've also fixed the unit test for |
Now it seems works fine for me, thanks for fast fixes! |
libtorrent version: 1.2
os: macosx 10.13.6
I create torrent-file of some macosx framework, which have symlinks to internal folders (SDL2 Framework for example).
To create torrent-file i use make_torrent tool using -l key. I checked it by dump_torrent tool, and can see valid symlinks inside.
But when i try download data using that .torrent-file by libtorrent, it creates zero-sized files instead of symlinks...
Cannot find any related code in libtorrent sources, which create symlinks when downloading data.
Also cannot find any info about it in documentation, so i guess it is not a normal behavior.
(zipped torrent-file attached).
tt2macosx.zip
The text was updated successfully, but these errors were encountered: