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: Sesquipedalian on Aug 15, '12 10:29:09AM

http://en.wikipedia.org/wiki/Hard_link
http://en.wikipedia.org/wiki/Symbolic_link
http://en.wikipedia.org/wiki/Alias_(Mac_OS)

Basically, with a hard link, the same file data exists in two places at once. So ~/Documents/myfile.txt and ~/Dropbox/myfile.txt are both names for the same data; editing ~/Documents/myfile.txt will instantly change the data in ~/Dropbox/myfile.txt too, because it is the same data. Hard links work perfectly 100% of the time for all operations, even if you move or rename files, but can only be used within a single filesystem (you can't make a hard link to a file on another disk), and cannot be used for folders.

A symlink is a small file that redirects to another file or folder. When you try to open/copy/delete/whatever a symlink, your actions simply get sent to the path that the symlink points to and applied to whatever is found there. Symlinks can point to files and folders, can point to items on other disks, and work for almost all operations. But they are pretty dumb; if you move or rename the file that the symlink points to, the symlink will be broken, because it now points to nothing.

An alias is a pointer (like a symlink). It is able to point to files, folders, other computers on network, and more. An alias is usually able to find its target even if the target moves or is renamed, which makes aliases much more robust than symlinks. However, aliases are Mac specific (they were invented for use by the Finder) and don't usually work with low-level operations (e.g. UNIX command line programs).

Dropbox uses various low-level operations to do its magic, and so it can't follow aliases. Putting an alias file into your Dropbox folder will result only in the alias file itself getting uploaded to Dropbox.

[ Reply to This | # ]

Use symbolic links in a Dropbox folder
Authored by: Interactive on Aug 15, '12 11:28:39AM
Thank you, Sesquipedalian, for taking the time to explain the difference. Your explanation is clearer than the general information found at other places, particularly with aliases in OS X.

I created a folder on Dropbox that contains (1) an Excel spreadsheet that keeps track of my students' grades and (2) other course-related folders and files. Then, on my home Mac and on my work Mac, I created an alias on the Desktop that points to the folder on Dropbox.

This way, if I changed data in the spreadsheet, for example, while at work, then when I return home and access the spreadsheet from the folder alias on the Desktop, the updated spreadsheet is there. That is, the originals always reside on Dropbox.

This use of aliases is the reverse of what you warned me about in your last paragraph. But, this is OK, isn't it? Or, does it have a potential for issues?

[ Reply to This | # ]
Use symbolic links in a Dropbox folder
Authored by: leamanc on Aug 15, '12 08:53:33PM

The alias will only work on the Mac you created the alias on. On another computer linked to your Dropbox account, the alias file will copy to your Dropbox, but will be useless.

Symlinks are covered in the Dropbox documentation as the way to achieve what we're talking about here. While this hint is great and very well written, I would recommend that everyone who is interested in working with symlinks and Dropbox to just check out the Dropbox documentation.

[ Reply to This | # ]

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 | # ]