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
  • 32,861
  • 27
  • 118
  • 178
  • How is this about Ubuntu? – Nick Volynkin Apr 12 '16 at 17:35
  • 2
    @NickVolynkin I'm using dropbox on Ubuntu with Ubuntu hard links / symlinks. How is it not? – Tim Apr 13 '16 at 00:12
  • it's Dropbox on Linux/Debian with Unix symlinks. Answers will be the same for any Linux distribution. – Nick Volynkin Apr 13 '16 at 18:29
  • @NickVolynkin Yeah? Are the answers valid for Ubuntu? Yes. So it's on topic. I'd suggest you read the [help/on-topic] before suggesting questions like this aren't allowed here (they are). – Tim Apr 13 '16 at 18:34
  • hey, calm down.) – Nick Volynkin Apr 13 '16 at 18:39
  • Have 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?
    – andrew lorien Nov 15 '16 at 23:56
  • 1
    @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. – Tim Nov 16 '16 at 00:00
  • @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. – Jim Balter Dec 26 '21 at 12:10

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
  • 197,895
  • 55
  • 485
  • 740
andrew lorien
  • 1,353
  • 12
  • 14
  • So we could say that it breaks hardlinks in shared folders? – Falk Nov 17 '16 at 01:52
  • Yes. Hard links are broken, and soft links inside Dropbox are broken - but not until the file is changed. – andrew lorien Nov 17 '16 at 01:57
  • So 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 Nov 17 '16 at 02:04
  • I'll run this script tomorrow, it's 3o clock where I live. – Falk Nov 17 '16 at 02:06
  • Good 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... – andrew lorien Nov 17 '16 at 02:06
  • 1
    @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. – muru Nov 17 '16 at 02:19
  • @muru any magic sentence to use? Or do I just write hey look at Andrew's answer? – Falk Nov 17 '16 at 02:22
  • @Falk something like "Turns out this answer was mistaken, see Andrew's post (link) for the correct answer", maybe – muru Nov 17 '16 at 02:34
  • Thanks everybody. I just got my "Yearling" badge last week, so this was a nice validation. – andrew lorien Nov 18 '16 at 00:01
  • 1
    Dropbox changed how it handles symlinks mid-2019: https://help.dropbox.com/installs-integrations/sync-uploads/symlinks https://www.paulingraham.com/dropbox-and-symlinks.html – Jim Balter Dec 26 '21 at 12:26
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
  • 1
    I 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. – Mark Kirby Apr 12 '16 at 07:53
  • 1
    The 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. – Falk Apr 12 '16 at 10:05
  • But some things don't follow some links - does dropbox follow hard links (not do all apps, I need to know specifically). – Tim Apr 13 '16 at 00:13
  • Sure? what app does not "follow" hard links? – Falk Apr 13 '16 at 13:15
  • OwnCloud, a file syncing app. – Tim Apr 13 '16 at 13:27
  • OK, 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. – Falk Apr 13 '16 at 13:45
  • I voted this up, but then changed my mind after it was too late to remove my vote. See my answer below. – andrew lorien Nov 17 '16 at 01:44
  • The 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 Dec 26 '21 at 12:19