How to preserve ownership and permissions in Dropbox?

I have two machines, a Mac and a PC running Linux, that I am trying to keep a certain file synced between using Dropbox.

One of the files that I am syncing needs to be writable by another user (different UID on the same machine, not referring to another dropbox user) besides myself. To be more specific, this other UID is actually a daemon. So, either the file needs to be owned by that other user, or else write permission is needed for "group" and/or "other". Initially I have set it up this way on both machines. In addition, the directory containing the file is already owned (chmod 777) by the user that needs to have write access to the file.

However, whenever the file gets synced from one box to another, it appears that Dropbox completely ignores both sets of permissions, and changes the permissions on the newly updated file to be owned by me with permissions 0644 (rw for me, r for everyone else). If the file isn't owned by me it even changes ownership back to myself! As a result, the other user no longer has write permissions until I manually go in and re-chmod the file.

Additional things I have tried that have not worked:

  1. made sure the user account (for the "other user") on both machines has the same UID. Not sure why this would be necessary, since my primary account doesn't have the same UID on both machines.

  2. chmod u+s <dir> and chmod g+s <dir> where is the directory containing the file in question.

  3. changing ownership of the file to the other user and placing it outside the Dropbox directory, and creating a symlink to the file in the Dropbox directory. Dropbox actually deletes the symlink, leaves the original file (outside the Dropbox directory) unchanged, and creates a new copy of the file where the symlink used to be!

How can I set things up so that my permissions and/or ownership are preserved?


Solution 1:

Ok, here is the solution I have found. Whether or not this will work with future versions of Dropbox is uncertain. I have opened a service request with Dropbox to try to resolve the problem further.

Overall, the solution is a combination of two things:

  1. Setting the umask for the Dropbox process so that newly created files have permissions of 0660. This is user read/write, group read/write, other none.
  2. Setting the group for newly created files to the group that needs to have write access to the files in question.

This solution will apply to all files in the Dropbox folder, not just a single file. In my case this is acceptable.

Under Linux, I modify the /etc/init.d/dropbox startup script so that the line invoking dropbox as a daemon reads:

HOME="$HOMEDIR" start-stop-daemon --umask 0006 -b -o -c $dbuser:$dbgrp -S -u $dbuser -x $HOMEDIR/$DAEMON

Adding the --umask 0006 accomplishes setting the umask, and the :$dbgrp portion of the -c option accomplishes setting the group to that the daemon belongs to.

On the Mac side, I run the following commands:

ps aux | grep -i dropbox

From this I can see the command-line options that started Dropbox and from this I extract the $mydropboxid used later. Then I quit Dropbox and open a command prompt and enter the following commands:

umask 0006
/Applications/Dropbox.app/Contents/MacOS/Dropbox -psn_0_$mydropboxid &
exit

I plan to automate the above commands at some point so that I won't have to re-run these any time my machine is rebooted.

This handles setting the mask for newly created files so the group for a file has write access. However, in order to get the group set correctly I need to setgid the Dropbox cache directory - this so far has only needed to be done once:

sudo chgrp -R $dbgrp ~/Dropbox/.dropbox.cache
sudo chmod -R g+s ~/Dropbox/.dropbox.cache

It appears that all new files are first created under the ~/Dropbox/.dropbox.cache directory, so the above commands gives those new files the proper ownership and permissions that new files created by Dropbox has the correct group.