Good guess, but that wasn't the issue, even though it would have made a lot of sense. It's unfortunate I left that part of the code in there, but the user actually tested my App Store app with and without unlocking locked files (the app contains a switch for that), which didn't help, and they sent me plenty of screenshots and videos which show that the files are not locked.
So, I took another pass at this and I think I found the problem. There is actually a known bug (r.129627798) similar to this in our smb server that was fixed in macOS 26. Basically, the way delete works in smb is that the client accesses the file with a "DELETE_ON_CLOSE" option, then closes the file to trigger the delete. The server tracks open file references and then deletes the file when the count reaches 0. Unfortunately, there was an issue in our file closing logic which could cause the server to keep the count "high" longer than it should, leading to the problem you're seeing.
I've mentioned that this was happening on our server, but part of our own testing showed that other servers were failing under the same conditions, so the bug isn't unique to us. I'd also highlight that NAS boxes are often updated very infrequently (if at all), increasing the likelihood of problems.
I think I can also explain this:
Actually, what prompted me to write this post and I forgot to mention is that the user told me that they can remove the folders without errors in the Finder.
Unfortunately, I think this is a case of one problem hiding another. The Finder's current delete logic on smb is significantly slower and more complicated than it really should be. I haven't tested this myself, but I suspect that a comparison between NSFileManager and the Finder will show that NSFileManager is considerably faster.
This is an issue we're working on (r.153221920). However, I think that extra complexity and delay end up hiding/preventing the problem you're seeing. I suspect the same dynamic is playing out with your own implementation. It's probably faster than the Finder and significantly slower than NSFileManager, but it also ends up generating a different series of SMB operations. The combination of those factors means that it masks the problem the same way the Finder does.
In terms of what you do about it, that's a harder question to answer. My initial thought was that you should:
Unfortunately, having done a bit more testing on our own bug, I'm not convinced that will work. Based on the testing I've done using rm and the Finder, the Finder is initially able to delete the directory, but doing rm first ends up creating a directory state that the Finder can't delete either. For the moment at least, I think your best option is to just ship your own delete function.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware