Catalina Keeps Deleting Documents Symbolic Link

I have a symbolic link from ~/Documents to ~/Dropbox/MyDocuments.

However I noticed that Catalina from time to time deletes my symbolic link and replaces it with a new Documents folder. I think its happening at a reboot but may happen at other times as well. Any way to prevent this


Solution 1:

I have found a workaround for this that I got from the Dropbox forum. As for many years, I 've been syncing my Desktop using Dropbox. However, because of the new layer of security in Catalina, it deletes the folder.

Here is a solution that I did it and it is fine for me now.

After creating the symlink to my Dropbox desktop folder, I locked the link file by displaying its info and checking the 'Locked' checkbox. That seems to do the trick. I checked that I can still write and save to my desktop.

Link: Dropbox Symlinks

Solution 2:

Locking the symlink as root, as others have mentioned, is the answer. This can all be done from a script so you don't have to enable and log into the root account.

Here is a simple script I wrote that needs to be run as root (with sudo) that takes two arguments:

  1. Short username
  2. Name of your OneDrive folder (Just OneDrive for personal OneDrive accounts)

This script will:

  1. Create a Desktop and Documents folder in the specified OneDrive folder
  2. Copy all items from your existing Desktop and Documents folders into OneDrive using rsync
  3. Delete your Desktop and Documents folders
  4. Symlink Desktop and Documents to OneDrive
  5. Lock the symlinks themselves so they aren't deleted on login/reboot

Warning:

This script doesn't do any error checking or folder existence verification. It might delete all of your files. Make sure you have a backup.

#!/bin/bash

if [[ $# -lt 2 ]] ; then
    echo "Scipt requires two arguments:"
    echo "Argument 1. Short username"
    echo "Argument 2. Name of OneDrive folder"
    exit 1
fi

shortname=$1
onedrive=$2

#########
# DESKTOP
#########

# Make Desktop folder in OneDrive
mkdir -p "/Users/$shortname/$onedrive/Desktop"

# Copy all files from existing Desktop folder to OneDrive Desktop folder
rsync -havux --progress --stats "/Users/$shortname/Desktop" "/Users/$shortname/$onedrive/Desktop"

# Remove existing Desktop folder
rm -rf "/Users/$shortname/Desktop"

# Create symlink to Desktop folder in OneDrive
ln -s "/Users/$shortname/$onedrive/Desktop" "/Users/$shortname/Desktop"

# Set the symlink itself (-h flag) to system locked. (User locked would be uchg)
chflags -h schg "/Users/$shortname/Desktop"

###########
# DOCUMENTS
###########

# Make Documents folder in OneDrive
mkdir -p "/Users/$shortname/$onedrive/Documents"

# Copy all files from existing Documents folder to OneDrive Documents folder
rsync -havux --progress --stats "/Users/$shortname/Documents" "/Users/$shortname/$onedrive/Documents"

# Remove existing Documents folder
rm -rf "/Users/$shortname/Documents"

# Create symlink to Documents folder in OneDrive
ln -s "/Users/$shortname/$onedrive/Documents" "/Users/$shortname/Documents"

# Set the symlink itself (-h flag) to system locked. (User locked would be uchg)
chflags -h schg "/Users/$shortname/Documents"