Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Use symbolic links in a Dropbox folder ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use symbolic links in a Dropbox folder
Authored by: leichter on Aug 19, '12 11:31:52AM

There's a subtle point that, once you understand it, makes symlinks much more useful in Dropbox.

The whole design of symlinks in Unix tries to make them invisible to programs that don't specifically try to manipulate them. So suppose 'sym' is a symlink to 'file'. If a program opens 'sym' for read, it actually gets the data in 'file'. If it appends to 'sym', it actually appends to 'file'. However, if it deletes 'sym', what disappears is the link 'sym', not the file 'file'. Opening 'sym' for writing as a new file - not appending to it - is equivalent to deleting the old file and creating a new one: It leaves 'file' unchanged and creates an entirely new file named 'sym' which no longer has any connection with 'file'.

A link to a directory follows the same rules. Looking a file up using the symlink as the name really searches the linked-to directory. Creating a file through the symlink is like appending: It creates the entry in the linked directory. And so on.

A program that wishes to do something special - like change where a symlink points - has to be aware that it's dealing with a symlink and use special OS calls for that exact purpose.

Dropbox works with symlinks *but it doesn't do anything special with them*. So suppose you put that 'sym' linked to 'file' in your Dropbox directory. Dropbox comes along, finds a new file, and sends it to its servers. What does it send? Well, first the name 'sym', and then the "contents" - i.e., what it gets from reading 'sym' which is exactly the contents of 'file'. On the server, and then later on other clients, what you will find is a normal file named 'sym' with the contents of 'file'. *There is no connection with a file named 'file'.* If you change 'file' on the system where 'sym' links to it, the changes propagate. If you change it anywhere else, the changes propagate back - but Dropbox doesn't modify files in place, it writes entire new ones. So the effect back on the original system is to break the link and write a new file named 'sym' with the latest contents - but no connection to 'file'.

I know of no way to keep a link to a *file* as a symlink across updates. But the story is different for *directories*. Unlike ordinary files, directories are normally updated in place (unless you explicit delete and recreate them). So you can do the following:

1. Create directory 'dir' anywhere you like.
2. Create symlink 'dirlink' pointing to 'dir' in your Dropbox folder.
3. Wait for 'dirlink' to appear on all other clients. It will appear as an ordinary directory, not as a symlink. If the original 'dir' had files in it, those will now appear as files on the clients, too.
4. On each client, rename 'dirlink' to 'dir' *in the place you want it to appear in your directory tree*. (Renaming only works if you are staying not the same device. Otherwise, you need to create 'dir' and move all the files.) This need not be the same on all clients, though it's easier to keep track of if it is.
5. On each client, create symlink 'dirlink' pointing to 'dir'.

Now you have a 'dirlink' on each client, which will to Dropbox look like a subdirectory - and it will sync all the files in that "subdirectory". Changes made on any client to any file in 'dir' aka 'dirlink' will be synced to all the other clients as well. Files created or deleted in 'dir' will be created/deleted on every other client as well.

It's probably easiest to do all this while there are no files in 'dir'. Otherwise, Dropbox sometimes repeatedly syncs the same files until everything eventually settles down.

The limitations here:
- Some platforms (e.g., iOS) don't support symlinks. To them, 'dirlink' will just be an ordinary subdirectory.
- Any time you add a new client, you have to go through the process for that client. Certain reset operations in Dropbox - anything that requires re-syncing every file in the Dropbox folder on a client - will require the same, because Dropbox doesn't know how to *create* symlinks - it'll just create an ordinary subdirectories.

I've used this configuration for a couple of years. You have to watch out for the reset situations and such, but generally once you have it set up, it "just works".

-- Jerry

[ Reply to This | # ]