0

I'm a programmer diagnosing a customer's issue with our software. We're having some problems writing into the user's Documents folder in macOS Mojave 10.14.6.*

It turns out that the customer's ~/Documents folder is a symlink to itself, causing ELOOP errors when calling file APIs, and a Too many levels of symbolic links error when attempting to view its contents in the Terminal with the ls command.

Terminal output

However, in the Finder, the folder displays normally, and appears to contain 15GB of contents.

enter image description here

The first time we saw this issue I wrote it off as an unsolved mystery, but this is the second customer we have seen in the past few years with a Documents folder that is a symbolic link to itself.

So my questions are:

  1. How is this possible?
  2. What can cause this configuration? Is there any legitimate reason it might be configured this way?
  3. Is it safe to tell the user just to move all the contents somewhere safe, delete the folder, and then recreate it in the Finder?

* The path is obtained by passing NSDocumentDirectory into NSSearchPathForDirectoriesInDomain.

  • @klanomath Whoops. Edited question to include the version. (It's Mojave). The software is in no way connected to dev/coding, and the customer isn't a developer. – Rich Nov 22 '19 at 15:15
  • I would ask the customer to run the following commands: find -L $HOME/Documents -type l and diskutil verifyVolume / and send the output of the two commands back to you. (delete comment/edit reason: first find command was wrong) – klanomath Nov 22 '19 at 15:33
  • @klanomath Thanks for the suggestions. What are you looking for in the output of the two commands? – Rich Nov 22 '19 at 15:35
  • 1
    What happens if the Documents folder is dragged and dropped into a Terminal window? This pastes the path of the folder into the command line. – Thorbjørn Ravn Andersen Nov 24 '19 at 0:30
  • 1
    @ThorbjørnRavnAndersen As well as the recursive Documents symlink, the customer also has a folder named Documents<Space> which contained all their actual files. The difference wasn't visible in the Finder, but dragging it into the Terminal inserted a backslash escape, solving the mystery. Thank you! – Rich Nov 25 '19 at 16:52
1

How is this possible?

It's easy to mess up when using ln on the command line. A symlink to self is legal (though nonsensical) so you wouldn't get an error when creating it.

What can cause this configuration? Is there any legitimate reason it might be configured this way?

It's useless and should be removed. Once removed, they can create a new ~/Documents/ folder. If you're concerned about safety, keep in mind you can always drag things back from the trash.

Is it safe to tell the user just to move all the contents somewhere safe, delete the folder, and then recreate it in the Finder?

If it's a symlink to self then it has no contents, because it's just a self-referential symlink. It's not a folder, it's just a recursive symlink. Finder is showing some folder that's named Documents but that doesn't mean it's showing ~/Documents/. You could create a folder with that name anywhere and add it to the Finder sidebar.

It would probably help to ask the user to cmd-click on the folder name at the top of the Finder window. That will show where it's located:

Finder "Documents" window showing full folder path

| improve this answer | |
  • This answer would be quite encouraging, except the folder they’ve sent me screenshots of isn’t some random Documents folder they’ve added to the sidebar. It is /Users/[username]/Documents, and Finder does indeed report that it has contents, even though commands I’ve asked them to run in the terminal disagree. – Rich Nov 22 '19 at 23:21
  • Then you're missing some crucial detail(s). A directory and a symbolic link are two different things; a directory cannot also be a symlink, even to itself. A symbolic link can point to a directory, but then it's a symbolic link and not a directory. – Tom Harrington Nov 22 '19 at 23:59
  • The terminal reports it is a symbolic link that points to itself. The Finder displays it as a folder with contents. (See the screenshots I just added to the question). I don't understand how this is possible, and this is the main reason I asked my question. – Rich Nov 23 '19 at 22:50
  • You were right. The folder the customer was sending us screenshots of was indeed a completely different Folder. Specifically, it was one named Documents<Space>. Thanks for your help! – Rich Nov 25 '19 at 16:51
  • Ah, spaces in the name. Tricksy. – Tom Harrington Nov 25 '19 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .