-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Support for symlinks in mount / vfs #6337
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave the code a very quick review - great work :-)
It needs tests though, both in the vfs layer and in the mount layer. The mount tests are in vfs/vfstest/
and likely they will need some build constraints not to run on windows. Or maybe symlinks do work on windows - I don't know!
I don't see patches for cmd/cmount
? This is the variant which runs on Windows/Mac by default. It also runs on Linux too. You'll need -tags cmount
to build it.
a49cf94
to
93947d5
Compare
cmount support added. |
Great work :-) Let me know if you want help writing the tests. |
Thanks, that would be greatly appreciated. How do I build unit tests and run them ? |
ec881ce
to
8875f10
Compare
@ncw I just rebased atop master. |
There are probably two places that tests need to be added. The first is in To pick an example Line 500 in 1107da7
You can see this creates a test VFS, creates files in it, then checks to see the files are as required. So you'd want to create a symlink and check it comes back in the listing. You'll need to add tests to Then you need to write a higher level test here https://github.com/rclone/rclone/tree/master/vfs/vfstest - the files in here are tested against the VFS itself and against all the different mount types. You write tests here just by creating and manipulating files - this is done either with vfs methods or os methods - the test runner abstracts that away. That is quite a lot of tests I know, but it is the only way we keep such a complicated bit of software working. The VFS layer is by far the most complex bit of rclone and I often think its the bit of code I was only just clever enough to write and therefore it is too difficult for me to debug! One thing I noted is that this should probably be gated on a flag - I don't think you have that at the moment? |
Thanks for the hints, will have a look.
Right I do not have a flag for that. Will add it at some point in time ;) |
Hm, how would I trigger tests ? I tried |
You cd into the directory with the tests and run |
7ee5463
to
985268d
Compare
When can we get this merged? |
Not yet, while it works fine cache less, it cause troubles with the cache system due to the names translations. Also still writing the unit tests to ensure correctness |
@ncw v1.67 has come and gone, yet this PR is still open. Can we ever expect this amazing feature to make it into rclone? |
I would love to see this merged as well. |
I have rebased this PR. I'm going to go through it to see what needs to be done to it to get it merged. |
Thanks for your interest again in this area @ncw . |
Thank you for your work on this @pasnox I'm going to merge this into a new branch fix-2975-mount-symlinks as I'm going to work on it a bit before merging to master. In particular I'm going to push all the symlink logic into the vfs layer so there is no duplicated code in the mount/cmount/mount2. I'm haven't got my head around the windows support yet though. I'll merge this, then I'll push an updated version and post a beta for people to try. |
This will be used to enable links support for the various mount engines in a follow up commit.
We enable symlink support using the --links command line switch. On the VFS layer, symlinks always ends with the rclonelink suffix. This is because it is what we send/get to/from the remote layer. That mean than any regular operation like rename, remove etc on symlinks files always need to have their rclonelink suffix. That way, we don't mess the internal map of items and avoid lots of troubles. When symlink support is disabled, Symlink and Readlink functions will transparently manage ".rclonelink" files as regular files.
We enable symlink support using the --links command line switch. When symlink support is enabled, the mount backends will translate the name of the vfs symlinks files (truncating their rclonelink suffix). Also, operations like rename, symlink etc does not needs the rclonelink suffix, it is handled internally to pass it to the underlying low level VFS. When symlink support is disabled, Symlink and Readlink functions will transparently manage ".rclonelink" files as regular files. Fixes rclone#2975
Here is a beta of the current build if anyone wants to give it a try v1.69.0-beta.8381.204b90a79.fix-2975-mount-symlinks on branch fix-2975-mount-symlinks (uploaded in 15-30 mins) |
I've merged this to master now which means it will be in the latest beta in 15-30 minutes and released in v1.69 Thank you @pasnox Any more testing gratefully received :-) |
Great news @ncw ! |
@pasnox wrote
Thanks
Sure - this one should work https://beta.rclone.org/rclone-beta-latest-linux-arm.zip (or .deb or .rpm if you prefer)
I dedicated to get this merged. I think there are likely still problems under Windows but that is a fix for another day :-) |
Please delete pr-6337-mount-symlink / pasnox-symlinks branches, it's no more needed then. |
Done
Lots of people use winfsp but I think symlinks are much less used on Windows.
The symlinks can get stored in the VFS cache so using The OS should cache them also so they shouldn't get read too often, but I didn't measure performance, I was more worried about correctness for this pass. |
I tested over a sftp remote (no cache) and it worked fine.
So far for me, it seems to works great. |
Thanks for testing @pasnox much appreciated I think those corner case tests got lost in the code reshuffle, alas Can you make an issue about the problem please so we don't forget - thank you . Do you want to have a go at fixing? |
I will have no time for that sorry, please go ahead, most likely reading the original PR code should show how exactly it's to be checked. |
What is the purpose of this change?
Add mount / vfs symlink support
Please, note that it has only been tested with storj backend on linux.
Especially, macOS, windows were not tested.
Please do test those platforms and any other backends !!!
Was the change discussed in an issue or in the forum before?
#2975
Checklist
Notes
The whole work has been (trashed mostly) refactored. They were flaws in the previous implementation, especially trying to use truncated names in the vfs dir internal nodes names which lead to inconsistency when it comes to push changes to the remotes.
For this reason, the refactoring went in 2 parts:
Add symlinks support in the VFS itself, in the form of always storing symlinks with the .rclonelink suffix, those being regular files.
The VFS Readlink and Symlink additions allow support for symlinks, even if the --links command line switch is not enabled, it's just a mater of creating a .rclonelink regular file with the target inside.
The only difference is that when --link is enabled, the VFS nodes Mode() would report the os.ModeSymlink flag hint.
This approach limit adding regressions in the VFS itself as there is no more names tweaking.
Some more checks were also added, to avoid to allow creating / moving files / links / directories names that would clash.
By example, the VFS must not be able to create in the same directory something called Hello.txt and something called Hello.txt.rclonelink, this is because when using the mount operation with --links enabled, we would end up with both files claiming the same node name: Hello.txt.
Add symlinks support in the mount backends, they are required to translate from the full vfs names into truncated names to the end user: Test.rclonelink would be seen as Test.
When --links command line switch is enabled, the file system will translate any *.rclonelink files into * links.
On the other hand, if --links is disabled, the symlinks will be seen as regular files, with their .rclonelink suffix which content contains the target file path.
Those changes comes with a rather big TestSymlinks unit test, which test all possible api and combinations.
The tests are ran for a VFS and each backends, with and without --links command line switch enabled, covering all possible scenarios.
I did run the tests successfully using this bash script: