Network disconnect causes leftover directory under /Volumes I have the following issue on Snow Leopard (10.6.8) after mounting a network drive (⌘+K in Finder. When I disconnect the laptop from the network without dismounting the drive, I get the Finder notification that the drive is no longer available, where I usually click "Disconnect All". This still leaves a leftover directory in /Volumes, which doesn't get deleted.

So if I mount the drive foo, a directory /Volumes/foo is created for the mount. This directory is still there after disconnecting the network cable and confirming to disconnect the drive. The next time I mount the same foo share, a new directory /Volumes/foo-1 is created etc.

This is causing some trouble with scripts (or Unison, which I point to /Volumes/foo), since the expected mount point is not the same (/Volumes/foo is empty in this case).

Is there any way to automatically remove this directory after the disconnect I described above?

This happens to me on a regular basis when I put the MacBook to sleep, remove the network cable and then want to work e.g. on the train without being connected to the network.

Update
After observing this issue for a couple of months now (I'm still on Snow Leopard), I've noticed the following: The folder /Volumes/foo is not removed even with the network cable in when removing the mount through Finder. To clarify:


Open Finder, press ⌘+K
Select a Samba drive to mount, e.g. smb://server/foo
This will be mounted in /Volumes/foo, make sure you can browse it through Finder
Click the Eject button next to the share in Finder
The directory /Volumes/foo is not removed


As a consequence, when I try to mount the same share again, another directory /Volumes/foo-1 is created, etc.
Not an answer, just to let you know that I cannot emulate your problem in a similar setup, and that you might have a problem.

I have an iMac with 10.6.8 and a MacBook with 10.8.1. Sometimes I forget to eject the connected volume on the iMac before I shut down the MacBook, and then the mounted volume remains as an image on the Desktop and in the sidebar of any open folder. I then simply click the eject-symbol in the folder sidebar or right-click on the desktop symbol and tell finder to eject the volume. It disappears. Now, looking in my /Volumes (in Finder as well as in Terminal), there is no remaining network volume. Maybe ejecting it did the trick.

Now, if I do NOT eject the remaining volume after I shut down the MacBook (or put it to sleep) and then boot (or wake) it and connect it again, the remaining volume icon on the desktop disappears and a new one appears. If I check under /Volumes (in Finder and Terminal), there is only one connected volume. (I did not shut down the iMac or do anything, except shut down the MacBook and start it (or put it to sleep and wake it) and connect it again.)

I do not get a Finder notification, that the drive is no longer available, either. If I try and access the disconnected drive by double clicking on the icon on the desktop, I can even browse its contents, until it automatically disappears when I reach I point where I have not been during this connection (open a subfolder that has not yet been opened).