desktop icon indicating copy to clipboard operation
desktop copied to clipboard

Syncing symbolic links as reference

Open david-jointech opened this issue 7 years ago • 76 comments

Currently when I add a symlink inside my Nextcloud folder it doesn't sync because "Symbolic links are not supported in syncing". I am trying to use Nextcloud as a home for my data, to have it synced between my PCs. Now I'd also like to be able to access my git-repositories (mostly) code via the directory-structure in Nextcloud but I don't want to sync the git-repositories via Nextcloud. This is why it would be really nice for me to be able syncing only the link to the repository which is on a fixed position on any system. eg: ~/Nextcloud/current_projects/fizzbuzz would point to ~/repositories/fizzbuzz. If I happen to be on a system where this git-repository isn't present I can just clone the repository there. This option could be optional (like the syncing of hidden files).

There's also a issue about this for the owncloud-client here: https://github.com/owncloud/client/issues/1440

david-jointech avatar Apr 17 '18 06:04 david-jointech

I see the use case, but we also would have to deal with windows links on mac, mac links on Linux... you get the drill. So between confusion and technical difficulty, and adding that most users don't even use symlinks all that much, this mostly seems a low-priority thing for me. Of course, anyone is free to work on it but he/she will have to do a full (cross-platform) solution, and that won't be easy.

camilasan avatar Apr 17 '18 08:04 camilasan

For reference: https://help.nextcloud.com/t/symbolic-link-support/220/27

camilasan avatar Apr 17 '18 09:04 camilasan

Would the proposed implementation in point three of this post https://help.nextcloud.com/t/symbolic-link-support/220/18?u=callegar be a viable way to solve the problem?

david-jointech avatar Apr 17 '18 09:04 david-jointech

I agree with the arguments mentioned in the link above. a symbolic link is a very useful way (especially on Linux) to extend local storage capacity using other partitions and / or disk. at least on Linux the nextcloud client shouldn't exclude links as these are transparent to all Linux programs

ferdiga avatar Apr 17 '18 20:04 ferdiga

I understand the difficult involved but I would love to see a solution to this. Or at least an option to sync links across compatible platforms...

I use symlinks to sort a very large image collection that I use for drawing practice into smaller collections, which lets me have image sets exist in multiple collections, it is very useful and intuitive but would be even better if it synced.

nefelin avatar Sep 05 '18 19:09 nefelin

I see the use case, but we also would have to deal with windows links on mac, mac links on Linux... you get the drill.

Are you saying that if Nextcloud were to support symlinks, it would have to be able to convert them to *.lnk files on Windows? Converting between symlinks and *.lnk files is impossible in either direction, simply because you can't find a generic way of converting between paths on Linux and paths of Windows in either direction. Why not simply only create symlinks on the other system if it's also a Unix-like system? You can't unify Windows with the rest. They chose to be fundamentally incompatible with Linux / Mac / FreeBSD / OpenBSD / Solaris / whatever.

On the windows client, you can choose between:

  • doing nothing
  • dumping a file there that states where the link leads on a Unix-like system

I suppose you currently just dump Windows' *.lnk files as what they are on Unix-like systems, even if they are of no use there (well, they hardly are of any use on Windows too because they can't be used in the middle of paths, but that's a different topic).

m1cm1c avatar Sep 20 '18 19:09 m1cm1c

No one is asking for conversion between symlinks and "windows links". There is no one-to-one comparison anyway. The dream solution here is to just not care that you found a symlink on linux and just treat it normally. If its a folder, its just a folder - extending storage. I can`t understand why the nextcloud client is hindering this to begin with, as you would have to actively disallow it.

EDIT: This is actually making it hard to use this cloud for me at all. I absolutely needed this feature to work exactly like Dropbox (and others).

fwsGonzo avatar Oct 07 '18 20:10 fwsGonzo

I agree that this is needed. I would go as far as to say that ignoring symlinks is a bug. Like was mentioned above, a symlinked file/folder can simply be treated as a normal file/folder; you have to intentionally go out of your way to avoid doing so (by using lstat() instead of stat(), for instance).

I don't think anybody is asking for the symlink itself to be represented on the cloud-side, moreso just simply recognized by the client side.

piranhaphish avatar Oct 11 '18 21:10 piranhaphish

I actually was asking for symlinks to be synced as "symlinks" and not to sync the content. The main reason for me is that I want to work out of my nextcloud-directory by default (I have an organization system in place there) but I do not want to sync git-repositories via nextcloud.

david-jointech avatar Oct 12 '18 15:10 david-jointech

Such a Feature would be awesome. So many times it would come handy and today again.

AncalagonTheBlack avatar Oct 31 '18 19:10 AncalagonTheBlack

I've noticed some seemingly random behaviour of my nextcloud-client 2.5.0 on Ubuntu (installed from nextcloud-devs PPA) with respect to symlinked folders inside a synchronised folder.

I first noticed that files in some local folder A which was not synced itself, but was symlinked from inside a synced folder S_local seemed to have disappeared by themselves. I looked into it and found that in the local synced folder S_local i had a symlink A to the "external" folder A, but in the remote synced folder S_remote there was an actual non-empty subfolder A (with the same name) in that place. When trying to sync, the nextcloud client was simply wiping the contents in my local folder A (which was just symlinked from inside S_local), and it was not downloading anywhere the contents of the remote actual folder A.

So far i didn't manage to reproduce this behaviour with a fresh folder (but i can reproduce it in the A folder). However, i observed some other strange behaviour. For example, i have currently a symlink to a folder locally, but a real folder with the same name remotely, and their contents is only partially synchronising.

Is this related to any known bug? I am not ready to report it myself, because i cannot yet reproduce the file-eating behaviour from scratch.

alexeymuranov avatar Nov 27 '18 18:11 alexeymuranov

After some more investigation, i decided to report the problems i observed, because when synchronisation client removes files for no reason, it is a serious problem IMO: #899.

alexeymuranov avatar Nov 27 '18 23:11 alexeymuranov

Like many others I also need to sync my folders via symlinks and request this important feature. From what I read above there are no good reasons not to support it and other cloud clients like Dropbox and tools like rsync support it, too. It is also not necessary to support all platforms at once. You can start with one platform and later others. One just needs to start and it is a rather simple thing to do. So what are the plans?

fkbreitl avatar Jan 25 '19 22:01 fkbreitl

Some ideas might come from this recent update to rclone

sphakka avatar Feb 01 '19 14:02 sphakka

EDIT 2023-10-22: This node is actually for Symlink dereferencing https://github.com/nextcloud/desktop/issues/3335 removed comment see referred issue

basos9 avatar Feb 03 '19 10:02 basos9

I'm actually having this problem with the client right now. It has for a long time complained to me about symlinks but now it's refusing to sync them at all, which is causing problems for me. Any suggestions on how to fix this in the short term please let me know!

jcklpe avatar Feb 15 '19 22:02 jcklpe

On the point that is commonly being raised as a counter re crossplatform; it's worth noting that Windows/NFTS -does- support symlinks (and hardlinks, can we please preserve hardlinks while we're at it) which are read and followed same as linux. It's had this support for years and years but hardly anyone uses them. Lately MS has been desparatly trying to claw back a developer user base that was migrating away so they've made the symlinks more obvious; and seem to have removed the previously required privilege escalation required to use them, so sym and hardlinks are a 1st class citizen on windows. .lnk files should not factor into this feature request at all.

It's been many years since I've been on a mac though, so I'm not sure what proprietary nonsense apple is doing, but osx is bsd, and last I checked it also still used sym and hardlinks under the covers (ln / ln -s command at least, I assume the fundamental node created on the HDD is the same)

(Edit: for people wanting a nice explorer ui for handling links on windows; http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html is an amazing bit of software and a day one installation for me on any fresh windows setup)

ricketyboo avatar Apr 22 '19 11:04 ricketyboo

I can confirm the moves by MS to include symlinks and hardlinks more and the link shell extension linked by rcuddy is cray invaluable. Highly recommend!

jcklpe avatar Apr 23 '19 20:04 jcklpe

On the point that is commonly being raised as a counter re crossplatform; it's worth noting that Windows/NFTS -does- support symlinks (and hardlinks, can we please preserve hardlinks while we're at it) which are read and followed same as linux.

I really would like to emphasize this point by rcuddy. Symbolic links are super valuable as-is, which is why Microsoft has supported them for a long time. While symbolic links weren't originally supported in Windows XP, they have been supported since Vista. NTFS has full support for both symlinks and hardlinks (and junctions!). Microsoft initially made the mistake of requiring admin privileges to create symlinks, mostly out of fear of how Windows XP apps would react to symlinks. But Microsoft has now realized that symlinks has fantastic value when organizing the filesystem (just see how ubiquitous symlinks are Linux!). Microsoft has steadily been making it easier and easier for normal users to create symbolic links. (Last I checked, to allow normal users to create symlinks, you still either had to enable "developer mode", or use "Local Security Policies" to allow non-admin users to create them. But I imagine Microsoft will eventually remove this restriction - and until then, it wouldn't be too difficult to just ask NextCloud users to configure this if they want to synchronize symlinks.)

My recommendation is as follows:

Preserve symbolic links, as-is. Relative symbolic links are practically the same on all systems. That is, if I have a relative symlink pointing to ../very/deep/sub/directory/, that symlink can be preserved across all systems. Absolute symlinks are perhaps a bit trickier because of the NTFS drive-letter prefix (although Windows also support "absolute" paths without a drive letter, e.g. cd \Users to go to C:\Users if you are working on the C-drive, and D:\Users if you are on the D-drive). My recommendation would be to ignore symbolic links with a drive-letter specification, with an option to strip the drive-prefix (e.g. C:\Users is converted to /Users). Alternatively, absolute symlinks could be ignored entirely.

If people wants to "sync folders outside the NextCloud folder", NTFS junction points is the obvious solution: They are basically directory hardlinks*, but can be used to link to directories on other drives/partitions.

(*Junctions are not actually hardlinks, since making actual directory hardlinks opens a can of worms. Junction points uses NTFS "reparse points", which basically tells the software to stop and reparse the path in a specific way, depending on the type of reparse point.)

Of course, it would also be possible to just have client-side settings to configure the symlink sync behavior, e.g.

  • Relative symlink:   ☒ Sync, as-is   ☐ Sync, dereferencing link   ☐ Ignore.
  • Absolute symlink: ☐ Sync, as-is   ☐ Sync, dereferencing link   ☒ Ignore.

PS: Windows' .lnk shortcut files have always been an inferior substitute for symbolic links: They must be referencing an absolute path, and they cannot be traversed/followed by e.g. the terminal/command prompt or search utilities.

Refs:

  • https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
  • https://www.tuxera.com/community/ntfs-3g-advanced/junction-points-and-symbolic-links/
  • https://www.2brightsparks.com/resources/articles/NTFS-Hard-Links-Junctions-and-Symbolic-Links.pdf

scholer avatar May 07 '19 18:05 scholer

Hi there, just want to provide my use-case where I don't want NextCloud to follow the symlinks and synchronize their content:

I have this big "Code" directory (with 100MB+ CSVs and the like) that has been causing constant 100% CPU from NextCloud for a while. You might know that it is not trivial to exclude a folder from synchronization locally (to ask NextCloud to stop trying to upload a folder to the server). Following suggestions in the aforementioned Reddit thread, I just moved my "Code" folder outside of the synced directory, and created a symlink to its previous location. This solved my problem. So I'm glad symlinks are not followed by NextCloud, as I don't see any other easy solution to prevent uploading subfolders of the synced directory.

Adrien-Luxey avatar May 13 '19 08:05 Adrien-Luxey

Have you tried ignore files (Settings->General->Edit Ignored Files) ?

image

basos9 avatar May 13 '19 10:05 basos9

@Adrien-Luxey If the directories have unique names, you can simply add their names to the ignore list @basos9 mentioned. If you have this use case several times, you can simply create an ending for these directories. For example, I sync my entire ~/Documents directory which happens to include quite a few git repos that I don't want to sync but want to exist uniquely on my different computers. So i simply created an extension .gitty for them and added *.gitty to the ignore list.

m1cm1c avatar May 13 '19 10:05 m1cm1c

Thanks @basos9 and @m1cm1c for your answers. Your solution is quite swell, @m1cm1c, although it's as hacky as mine. It shows that the folder exclusion is really a missing feature (e.g. why not accept full paths in the exclusion list?). Anyway, when you end up merging #1067, it won't hurt people using symlinks to exclude folders, as it will only cause more synchronization and not content destruction. I'll switch to @m1cm1c's suggestion then.

Adrien-Luxey avatar May 13 '19 14:05 Adrien-Luxey

@Adrien-Luxey I recently had some problems getting the ignore list set up correctly but I finally got specific folders excluded like this:

**/the-name-of-the-folder-you-want-to-exclude/**
**/if-you-need/you-can-use-multiple-folders-to/specify/**

jcklpe avatar May 14 '19 04:05 jcklpe

Ideal solution would be to not treat symlinks in any special way and just sync them. The best example is how git handles those.

RafalSkolasinski avatar Jun 04 '19 09:06 RafalSkolasinski

@RafalSkolasinski One could argue that not treating symlinks in any special way would be how Dropbox handles them, not like git handles them: To sync the contents of whatever they are linking to.

m1cm1c avatar Jun 13 '19 13:06 m1cm1c

IMO, rm and cp are not treating symlinks in any special way.

alexeymuranov avatar Jun 13 '19 14:06 alexeymuranov

@alexeymuranov I agree. However, I'd argue that the user's notion of what rm and cp are doing is quite different from what a cloud service is doing.

I think that:

  • The user's expectation of what rm is doing is to remove a subtree of a file system.
  • The user's expectation of what cp is doing is to duplicate a subtree of a file system to a different location.
  • The user's expectation of what a cloud service is doing is to keep in sync on different computers the data referred to in subtrees of file systems.

On the more practical side (potentially breaking the expectation of the majority of users), I see that both ways of treating symlinks have their use cases. Continuing not to sync them in any way is the worst way to proceed.

I think that the ideal solution would allow to user to specify the cloud service's behavior on a per-symlink basis. This could be done in files named .nextcloud_attributes* (the wildcard allowing for different ones of these files iterated over in asciibetical order to accumulate the total configuration). These files could also specify whether they themselves will be synced, allowing for a lot of use-case-specific flexibility.

m1cm1c avatar Jun 13 '19 14:06 m1cm1c

How about allowing person administrating the Nextcloud (or each user) specify this config it the the web interface?

RafalSkolasinski avatar Jun 13 '19 14:06 RafalSkolasinski

Can also easily be implemented in a way that allows per-element selection of whether it should be synced as a link or as a file/directory, so it sounds good to me. 👍

It could be done as an option on each element "from here on downwards, sync links as such/as files or directories" where options chosen further down the tree are dominant. These options should apply on the elements themselves already so that one can sync symlinks as such in a directory that itself is symlinked to on one if the machines it's synced to.

m1cm1c avatar Jun 13 '19 19:06 m1cm1c