I'm having issues deleting a directory on my macOS Mojave 10.14.3 system.
The filesystem is APFS and these are the symptoms:
$ rm -rf strange/
rm: strange/: Directory not empty
$ sudo rm -rf strange/
Password:
rm: strange/: Directory not empty
$ ls -lia strange/
total 0
786499 drwxr-xr-x 3 kk staff 96 Feb 26 18:56 .
430961 drwxr-xr-x+ 49 kk staff 1568 Feb 26 21:50 ..
$ ls -lid strange/
786499 drwxr-xr-x 3 kk staff 96 Feb 26 18:56 strange/
Notice that the link count for the directory is is 3. A freshly created empty directory has a link count of 2.
No other file or directory on the system has the same inode number (this was checked using sudo find / -inum 786499), and I believe that directories on APFS filesystems can't have additional hard links anyway (like they can with HFS+).
Putting the directory in the trash and emptying it returns a dialog with the text
The operation can’t be completed because the item “strange” is in use.
However, running sudo lsof "$HOME/strange" (after returning the directory to my home directory) returns nothing, and rebooting the machine changes nothing. Using sudo lsof +L1 (listing open files with a link count of zero, i.e. deleted files kept open by some application) also does not reveal any paths under the strange directory.
The directory does not have any ACLs or extended attributes:
$ ls -lde@ strange/
drwxr-xr-x 3 kk staff 96 Feb 26 18:56 strange/
Making a copy of the directory using the Finder creates strange copy. This copy directory has a link count of 2 and can be deleted. Curiously though, the "Get Info" dialog in Finder says that each directory (original and copy) contains an item (it usually reports zero items for freshly created empty directories).
$ ls -la strange*
strange:
total 0
drwxr-xr-x 3 kk staff 96 Feb 26 23:57 .
drwxr-xr-x+ 49 kk staff 1568 Feb 27 10:36 ..
strange copy:
total 0
drwxr-xr-x 2 kk staff 64 Feb 26 23:57 .
drwxr-xr-x+ 49 kk staff 1568 Feb 27 10:36 ..
Running "First Aid" using the macOS "Disk Utility" does not change anything (returns "Successful" at the end). This regardless of whether this is done on the live system or in Rescue Mode.
Running fsck_apfs -y on the disk in Rescue Mode mode does produce a number of warnings on one of the filesystem snapshots of the following type:
warning: Cross Check : Mismatch between extentref entry reference count (1) and calculated fsroot entry reference count (0) for extent (0x236654a + 4)
This does not seem to be repaired by fsck_apfs though.
Any clues as to how to go about deleting this directory?
For those who wonder, the directory was initially found as a subdirectory of a Steam game (Factorio, release 0.17.0). The original path of the directory was ~/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/data/base/campaigns/demo/locale/ru. The part from demo downwards caused the game to not start properly (it was, apart from the directories, empty, but the game tried to pick up some non-existing file from the demo directory and crashed). Moving the directory away made the game playable, but I later discovered that the bottom-most ru directory could not be deleted. This is the directory that I then renamed strange and that I refer to throughout this question.
I have submitted feedback to Apple about this, but I'm no Apple developer so I can't submit a formal bug report.

lsofhave shown it? – Kusalananda Feb 26 '19 at 22:39defaults write com.apple.finder AppleShowAllFiles YES– Rui F Ribeiro Feb 26 '19 at 22:41sudo lsof +L1to explicitly list any deleted-but-still-open files system-wide: a basiclsoftargeted to a specific directory will only report on files that are there, and a deleted file does not quite qualify. – Feb 27 '19 at 09:37chflags– Thomas Dickey Feb 27 '19 at 09:56nouchg,nohiddenornoschgwithchflagson the directory and its contents does absolutely nothing. I will try in single user mode though. – Kusalananda Feb 27 '19 at 10:07rusolved another issue (playing the game). When I later tried to actually delete therufolder, I failed. Hence this question. I have clarified this in the question. Thanks. – Kusalananda Feb 27 '19 at 17:18'#!/usr/bin/python
from Foundation import NSFileManager
fm = NSFileManager.defaultManager()
fm.removeItemAtPath_error_('/foo/bar', None)'
Create a python script file and chmod +x it, then run it in terminal. It's possible this higher level API might do the trick, if not, worth a shot. Replace foo/bar/ with your file path. It should look like this: https://imgur.com/a/G82XWhA
– chrisdahfuh Mar 01 '19 at 21:12lsisn'tls, so to speak, you've got a bigger problem. For reference:[MacBook-Pro:/bin]% shasum -a 256 -b ls c832fe1dc2c8ea1c871f5994916582ba735a56505d476ea5f16d1a8a8534724b *ls– Bill Horvath Mar 14 '19 at 17:54fsck_apfssimply isn't able to repair. – Kusalananda Mar 14 '19 at 18:00statreveal anything useful?stat -f "%N: %HT%SY" ./strange/*– Bill Horvath Mar 14 '19 at 18:11stat: ./strange/*: stat: No such file or directory. There is nothing to expand the*glob to, and there's no file in the directory that is in any way visible, not even withls -a. – Kusalananda Mar 14 '19 at 18:22fsck_apfsshould have fixed it (assuming that the disk was unmounted when it was run), and that the folks who suggested filing a bug report with Apple are right. It also appears that you may be able to fix it by wiping and reformatting the drive, reinstalling the OS, and restoring off a Time Machine backup, but that's a rather onerous process. (One other suggestion was formatting it as HFS+ and having the Mojave installer change the formatting. Ugh.) Any other ideas? – Bill Horvath Mar 15 '19 at 14:17