6

I have a folder of large files. I want that folder to be in two different places at once - my Home documents, and my College documents folder.

I've done this with a symlink in the College folder to the Home folder.

Unfortunately, Dropbox syncs my College folder - and my file space was quickly used up.

Does dropbox follow hard links, and if so, how do I create one?

Tim
  • 33,500

2 Answers2

5

No, it doesn't.

When you update a file, Dropbox breaks all links. So in the example @Falk gives above, if he edited that file from a remote computer, when it synced back the link would be broken, and Dropbox would contain a new file called testfile (Falks conflicted copy).

The only link which works is a soft link where the original file is the one in the dropbox folder. Here's the script I used to test:

# symlink with target inside dropbox
echo "symbolic link test" > ~/Dropbox/symlinkToDropbox.txt
ln -s  ~/Dropbox/symlinkToDropbox.txt ~/symlinkToDropbox.txt
cat ~/symlinkToDropbox.txt
echo "edit target of symlink" >> ~/Dropbox/symlinkToDropbox.txt
echo "edit symlink" >> ~/symlinkToDropbox.txt 
cat ~/symlinkToDropbox.txt 
cat ~/Dropbox/symlinkToDropbox.txt 
# symlink with target outside dropbox 
echo "symbolic link test" > ~/symlinkFromDropbox.txt
ln -s ~/symlinkFromDropbox.txt ~/Dropbox/symlinkFromDropbox.txt  # relative symlinks don't work
cat ~/Dropbox/symlinkFromDropbox.txt 
echo "edit target of symlink" >> ~/symlinkFromDropbox.txt
echo "edit symlink" >> ~/Dropbox/symlinkFromDropbox.txt
cat ~/symlinkFromDropbox.txt 
cat ~/Dropbox/symlinkFromDropbox.txt 
# hard link with target inside dropbox
echo "hard link test" > ~/Dropbox/hardlinkToDropbox.txt
ln ~/Dropbox/hardlinkToDropbox.txt ~/hardlinkToDropbox.txt
echo "edit target" >> ~/Dropbox/hardlinkToDropbox.txt 
echo "edit linked file" >> ~/hardlinkToDropbox.txt 
cat ~/hardlinkToDropbox.txt 
cat ~/Dropbox/hardlinkToDropbox.txt 
# hard link with target inside dropbox
echo "hard link test" > ~/hardlinkFromDropbox.txt
ln ~/hardlinkFromDropbox.txt  ~/Dropbox/hardlinkFromDropbox.txt
echo "edit linked file" >> ~/Dropbox/hardlinkFromDropbox.txt 
echo "edit target" >> ~/hardlinkFromDropbox.txt 
cat ~/Dropbox/hardlinkFromDropbox.txt 
cat ~/hardlinkFromDropbox.txt 
#all of that works fine.  
#But now open all of those files from your dropbox folder on another computer and edit them
#Your dropbox will sync, your local versions of all those files will be updated, but NONE OF THE LINKED FILES WILL UPDATE
#The hard links are replaced and the old versions copied as "conflicted copies"
#The symlink where the dropbox file was the link is unlinked

#the symlink where the dropbox file is the original is the only one that works
muru
  • 207,228
2

Turns out this answer was mistaken, see Andrew's post for the correct answer.

Yes I does.

I've tested it with a standard free dropbox account with the dropbox folder in a btrfs volume.

The test was:

ln /media/username/volume/Documents/testfile /media/username/volume/Dropbox/testfile
ls -li /media/username/volume/Documents/testfile
ls -li /media/username/volume/Dropbox/testfile

The first number from the ls -li command shows th inode number, the number between the permissions and the username is the link counter (shows how many hard links the file has).

Immediately after running the ln command the dropbox try icon showed activity, and effectively uploaded the test file.

I've also tested to make a second hard link inside the Dropbox folder and it also uploaded the file, I'm not sure if it's aware that's only one.

My test file is a small 18KB .ods file, but it should also work larger files.

About hard links and inodes:

When you create a hard link of a file you are giving it just a second name in a different folder (or the same if you like to).

This is files are not really placed in folders they are on the hard drive identified by an i-node (depends on the file-system type).

So what are folders?

Folder are just lists also identified by an i-node that contain the names of the files and other folders that are 'inside' of them. Each element in this list point to it's corresponding i-node.

So if you create hard links both/all point to the same i-node and therefore all of them are just files (the same one).

Be aware that some apps refuse to do their job with files that have hard links. Other apps may accidentally or intentionally break hard links turning one file with say 2 names into two files with one name each.

Wikipedia gives us a more info:

https://en.wikipedia.org/wiki/Hard_link

https://en.wikipedia.org/wiki/Inode

To create hard links you can use ln which is a command lines tool, You can use it like this:

ln TARGET LINK_NAME

Where target is the existing file and link_name the new name of the file. When you are done you can check with ls -li the i-node number of the file and see that both links have the same number.

Here is the man page: http://linux.die.net/man/1/ln

Falk
  • 198