“The operation can’t be completed because the item is in use” when deleting from Samba mounted drive

finderpermissionsmb

I have a USB drive plugged into my Asus RT-N66U router and shared over SMB. I originally formatted this drive on a Mac. I have two Trendnet TV-IP572PI surveillance cameras that records snapshots/video to this drive over SMB. Sometimes when I mount the drive from my Mac ('Connect to server' @ smb://192.168.1.1) and attempt to delete old directories off of it, I get this error:

The operation can’t be completed because you don’t have permission to access some of the items.

This is extremely frustrating since I have to unplug the USB drive, plug it back into my Mac, and format it to get it working again. I assume this is some kind of permissions problem, and when these permissions are messed up, the cameras aren't writing to the drive. I may not notice this for days if I have been out of town.

Searching Google for this error mostly turns up results about disabling a unix extensions setting in smb.conf on the server you are connecting to. I have no way to do this since the Samba server runs off of the Asus router. Email support from ASUS has not been helpful so far, with recommendations to upgrade the firmware and do a hard reset on the router (have latest firmware already). I believe this problem stems from mounting the drive from my Mac.

Thanks in advance.

Best Answer

There are actually two messages you're referring to:

"This operation can't be completed because the item is in use"

and

"The operation can’t be completed because you don’t have permission to access some of the items."

If you see the first one - I sometimes get that message too. Quite often this can be resolved by running: sudo lsof | grep <filename> in Terminal.app - obviously replace <filename> with the actual name of the file you're trying to delete. I typically get this when trying to empty the trash, but if the trash is not supported on the filesystem you have mounted, you may see it when trying to delete.

What lsof does is it lists all open files, and shows which process opened each of them. Quite often this will be a quick look process that opened the file and somehow didn't close it (it will do that when you display a list of movie files in Finder - it will then try to show you the first frame of the movie in the preview, and it's using Quick Look to do that).

Usually after running the lsof the files are closed (that's if lsof doesn't show anything), or I can just kill the quick look process and then empty the trash.

As for the other message - the best thing to do is to run ls -la <filename> or ls -lad <directory> to see the permissions on the file or the folder you're trying to remove. This may give you a better idea where the problem is.