I have a problem where deleting a folder symlink on a mounted Samba share also deletes the target folder's contents when accessed from my Macbook. This is actually a problem I have had for many years, and remains despite using different machines and operating systems versions.

Here is the sequence of events:

  1. touch foo/bar/1.txt
  2. Create a symlink to a folder on an Ubuntu machine, i.e. ln -s foo/bar bar2
  3. Mount the Samba share containing the bar 2 symlink on a Mac
  4. Delete the bar2 symlink via the Mac.
  5. The symlink bar2 will be deleted, but the file foo/bar/1.txt will also be gone. Any files or folders in foo/bar will be gone.

At the moment, I am running El Capitan, Ubuntu 16.04 with Samba 4.3.11.

I have the following options in my smb.conf which are the only thing that come to mind as possible involved: allow insecure wide links = yes unix extensions = no


Since windows file sharing and hence the original samba had no concept of symlinks it would normally delete all of the folder tree through a symlink. However you might try changing to unix extensions = yes as your OSX may understand this too.

From the page https://www.samba.org/samba/docs/man/manpages/smb.conf.5.html#UNIXEXTENSIONS

unix extensions (G)

This boolean parameter controls whether Samba implements the CIFS UNIX extensions, as defined by HP. These extensions enable Samba to better serve UNIX CIFS clients by supporting features such as symbolic links, hard links, etc... These extensions require a similarly enabled client, and are of no current use to Windows clients.

Note if this parameter is turned on, the wide links parameter will automatically be disabled.

See the parameter allow insecure wide links if you wish to change this coupling between the two parameters.

Default: unix extensions = yes

You may want to investigate the insecure wide links option more as you may want to turn that off to achieve the results you are after.

The above may still not work as you desire due to the way that many systems implement deleting a folder structure. Normally the sequence proceeds as

  1. client incorrectly detect object to be deleted is a folder structure instead of a symlink.
  2. client recursively proceed to the deepest levels of the tree and delete all contents of those folders.
  3. the client it works its way back from the deepest levels back to the folder you told it to delete, deleting those as it goes
  4. then finally once the folder is empty the client will send the command to delete the folder
  5. however because the folder is actually a symlink the host only deletes the symlink.

This is how the content of the target is deleted along with the symlink, but not the actual target folder.

Similarly when it is instructed to delete a symlinked file only the symlink is deleted. The issue with the symlinked folder structure is that the samba client sends the delete command to all of the content before instructing the server to delete the symlink to the folder.

  • Various combinations of turning unix extensions on/off and enabling/disabling wide links made no difference. So what I am experiencing is actually the expected behaviour? Let me recap to make sure I have this correct. When accessing a Samba share from OSX: 1. Deleting a file symlink only deletes the symlink. 2. Deleting a folder symlink deletes the symlink & the target folder's contents, but not the target folder itself. This results in an empty target folder. Very strange behaviour. One would then expect the target folder to also be deleted, not just emptied of its contents. – Max Pfleger Oct 30 '16 at 19:15
  • Yes, I finally understand now. Thank you very much. I am going to have to completely rethink how I have been using symlinked folders in my Samba shares. Thanks. – Max Pfleger Oct 31 '16 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.