Does dropbox sync hardlinks?
Solution 1
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
Solution 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
Related videos on Youtube
Tim
My name is Tim. I've graduated from the University of Nottingham with a First Class Computer Science BSc with Hons. In my spare time I do computer programming, often C or JavaScript, but also shell scripts, and answering questions on Stack Exchange. I used to spend most of my time on Ask Ubuntu; now I mostly browse the HNQ or Meta Stack Exchange. If you want to contact me it's [email protected] Do you need a reliable VPS? Try Digital Ocean. Sign up with this link for $10 free. One of my favourite sites is Kiva.org, a micro-funding organisation that allows people to lend money via the Internet to low-income entrepreneurs and students in over 80 countries. Kiva's mission is “to connect people through lending to alleviate poverty.” With just $25 you can make a difference - and 99% of loans are paid back in full - so you can lend again and again!
Updated on September 18, 2022Comments
-
Tim over 1 year
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?
-
Nick Volynkin about 8 yearsHow is this about Ubuntu?
-
Tim about 8 years@NickVolynkin I'm using dropbox on Ubuntu with Ubuntu hard links / symlinks. How is it not?
-
Nick Volynkin about 8 yearsit's Dropbox on Linux/Debian with Unix symlinks. Answers will be the same for any Linux distribution.
-
Tim about 8 years@NickVolynkin Yeah? Are the answers valid for Ubuntu? Yes. So it's on topic. I'd suggest you read the help center before suggesting questions like this aren't allowed here (they are).
-
Nick Volynkin about 8 yearshey, calm down.)
-
andrew lorien over 7 yearsHave you solved this? A hard link from a folder doesn't make sense (you can only hard link i-nodes=files). Were you planning to just link the individual files you need from your college folder, and did it work?
-
Tim over 7 years@andrewlorien I found that Dropbox had a memory leak when a syncing was included, casing memory usage to double each hour, leaving a crashed computer in the morning.
-
Jim Balter over 2 years@andrewlorien "A hard link from a folder doesn't make sense (you can only hard link i-nodes=files)." -- this is wrong ... directories are i-nodes. A hard link of a directory (not "folder") "makes sense" but is disallowed because it creates loops in the file system structure and means that the parent directory is not unique.
-
-
Mark Kirby about 8 yearsI don't think this answers the question. The question is "Does dropbox follow hard links" and you don't mention dropbox at all, you just go on a tangent about what are folders and inodes, the OP never asked "what is a hard link?" they asked about dropbox. Am I missing some thing in this answer? because, right now, it does not seem to answer the question.
-
Falk about 8 yearsThe point is that hard links look to aplications just like files because that's what they are. So Dropbox or any other app won't distinguish if it's a hard link or just a file with one single path. If you understand hard links you'll understand that Dropbox won't care about how the file ended up in it's folder.
-
Tim about 8 yearsBut some things don't follow some links - does dropbox follow hard links (not do all apps, I need to know specifically).
-
Falk about 8 yearsSure? what app does not "follow" hard links?
-
Falk about 8 yearsOK, you are right, OwnCloud doesn't handle files with multiple links, but Dropbox does, I've just tested it. I'm going to edit my answer.
-
andrew lorien over 7 yearsI voted this up, but then changed my mind after it was too late to remove my vote. See my answer below.
-
Falk over 7 yearsSo we could say that it breaks hardlinks in shared folders?
-
andrew lorien over 7 yearsYes. Hard links are broken, and soft links inside Dropbox are broken - but not until the file is changed.
-
Falk over 7 yearsSo you have proven me wrong, what am I supposed to do in a case like this? I don't see the option to remove my answer, should I edit it? Is it possible (for the op) to change the accepted answer?
-
Falk over 7 yearsI'll run this script tomorrow, it's 3o clock where I live.
-
andrew lorien over 7 yearsGood question. I'm only a little bit ahead of you in SO points, so i'm not sure. @muru looks like a bit of an expert...
-
muru over 7 years@Falk you can't delete an accepted answer. OP can accept another answer whenever they want. You can edit your answer to tell users to refer to this post instead.
-
Falk over 7 years@muru any magic sentence to use? Or do I just write hey look at Andrew's answer?
-
muru over 7 years@Falk something like "Turns out this answer was mistaken, see Andrew's post (link) for the correct answer", maybe
-
andrew lorien over 7 yearsThanks everybody. I just got my "Yearling" badge last week, so this was a nice validation.
-
Jim Balter over 2 yearsThe question isn't whether Dropbox follows hard links (how can it not ... that's a kernel function), it's whether it syncs them correctly, which is a totally different matter.
-
Jim Balter over 2 yearsDropbox changed how it handles symlinks mid-2019: help.dropbox.com/installs-integrations/sync-uploads/symlinks paulingraham.com/dropbox-and-symlinks.html