Cannot delete an empty directory in OSX

This post is a little lengthy, sorry. The short version is: I have a directory that I can't delete. Terminal gives, "input/output error," when I try to interact with it. I've scanned the disk for errors and none are found. The root of the problem seems to be that the system thinks this is a link, when in fact it's a directory. How can I delete it?

Story mode: I have a directory called "media" on my desktop, into which I mounted another directory via SSH (fuse/sshfs). The connection was lost while the directory was open. Finder crashed, and the directory disappeared from the desktop. It's still there, however:

Desktop mike$ ls -1  
media  
templates  
Desktop mike$ mkdir media  
mkdir: media: File exists 

Almost everything I try to do to the directory gives me an, "input/output" error:

Desktop mike$ ls -i  
ls: media: Input/output error  
Desktop mike$ sudo rm -rf media  
rm: media: Input/output error  
Desktop mike$ sudo unlink media  
unlink: media: Input/output error  
Desktop mike$ sudo chmod 777 media  
chmod: media: Input/output error  
Desktop mike$ touch media  
touch: media: Input/output error  
cd ./media  
cd: error retrieving current directory: getcwd: cannot access parent directories: Input/output error

I get the same if I try to remount the remote SSH directory:

fuse: bad mount point `./media/': Input/output error

Even though it's not visible on the desktop or in Finder, I can search and find it. Right-clicking the search result doesn't offer a delete option -- only open and properties. Properties shows created and modified time (correctly) and a blank icon. I can also chose to open the item, in which case it gives me:

"The alias 'media' can't be opened because the original item can't be found. Delete, Fix, or OK." 

When I try delete, the same dialog keeps popping back up; choosing fix asks to select a new item to link to. Doing this reports: "Unknown error -1407," which Google tells me means, "Expected a folder but got a file."

I can move the directory, but only if I keep it on the desktop:

Desktop mike$ mv ./media ./a  
Desktop mike$ ls -i  
ls: a: Input/output error  
Desktop mike$ mv ./a ../  
mv: cannot resolve a: /Users/mike/Desktop/a

Is there anyway I can delete this? Or at least convince the system that it's a directory and not a link?


Solution 1:

Sorry I didn't update after resolving this. I appreciate all of the informed replies. Turns out it was a pretty simple thing. Browsing Linux message boards, I found that this is a kind of known issue with mounting via sshfs.

https://bbs.archlinux.org/viewtopic.php?id=94725

I experienced every problem the OP describes in that thread, plus the issue of Finder hiding the mount point (maybe it can't stat it or something, so it just doesn't show it). "...the processes trying to access disconnected sshfs shares go into uninterruptible sleep." The quick fix is to stop sshfs. "killal sshfs" was sufficient for me. I suppose restarting would have worked, too.

Solution 2:

I just hit the same issue. Turns out this is currently listed as a bug on osxfuse. The workaround involves killing the sshfs process manually and then unmounting the remote directory. After that you can even delete local mount point.

Solution 3:

I guess the reason why you can't select "Repair Disk" on Disk Utility is because the problem is on your boot disk.

I would recommend one of the following:

  • If you are on OS X Lion (10.7), boot from the recovery partition (hold CMD-R when you start the machine), run Disk Utility from there, and try to repair the disk;
  • If you are on an older version of OS X, you can either boot from an external disk, or install AppleJack (freeware);
  • If all else fails, I would give a shot to DiskWarrior (not free, but still the tool I trust most when it comes to my data).