Unable to delete folder with phantom sub-folders / files

foldershard drive

I had a postgres database folder which I had sent to the trash. However, I've been unable to empty the trash because it gives me the following error:

The operation can’t be completed because the item “<item_name>” is in use.

I'm fairly certain I had shut down the database before moving the folder. Nevertheless, normally, I'd be able to restart the computer and these sorts of errors would dissipate: but in this case the error persists.

I've also noted some slow-downs and, suspecting disk issues, have run disk utility, which now gives the following error:

Checking the object map.
error: (oid 0x4000000231b5a) om: btn: invalid o_cksum (0xdbe7569c81c16ed7)
Object map is invalid.
The volume /dev/disk0s2 could not be verified completely.

When exploring the un-deletable folder I noticed that there are some phantom sub-folders (or files without extensions) in the directory. I can't see these from the terminal if using ls, and the only reason I noticed them is because when using the cd command to drill-down into the directory I sometimes use the tab key to auto-suggest / auto-complete the next level of nested directory names: when doing so, a whole bunch of phantom folders appears.

I am unable to delete these folders using the usual rm -r <dir> type of approach…, which simply gives the No such file or directory error, so I'm not really sure what to try next.

Any ideas for how to forcefully remove the phantom folders / files and get the disk back to normal?

It is an APFS Container / fusion drive consisting of SSD and spinning platter disks.

Best Answer

For anyone else coming across this issue. The solution entailed formatting the hard drive, after which disk utility was able to do its thing and the data could be restored.