This is not a bug; the POSIX specification explicitly allows this
behavior. If a filename is renamed during a readdir() session of a
directory, it is undefined where that neither, either, or both of the
new and old filenames will be returned.
And that's because there's no good way to do this without trashing the
performance of the system, especially when most applications don't
care. (Do you really want your entire system running significantly
slower, penalizing all other applications on your system, just because
of one stupid/badly-written application?) In order to do this, the
kernel would have to atomically snapshot the directory --- even one
which might be several megabytes in length, and store a copy of it in
memory, while the application calls readdir(). Several processes
could perform a denial-of-service attack by starting to call
readdir(), and then stopping. This would end up locking up huge
amounts of non-pageable system memory, and cause the system to come
down in a hurry.
Attachment:
PGP.sig
Description: This is a digitally signed message part