> Explorer keeps handles open to directories to get updates via
> ReadDirectoryChangesExW. It opens watched directories with
> shared delete access, so deleting the child succeeds. But as
> discussed above, the directory isn't unlinked from the parent
> until Explorer closes its handle.
In Windows 10, NTFS allows deleting an empty directory that's currently opened with shared-delete access, so this race condition will be increasingly less common. For example:
access = GENERIC_READ
sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
disposition = OPEN_EXISTING
flags = FILE_FLAG_BACKUP_SEMANTICS
os.mkdir('spam')
h = CreateFile('spam', access, sharing, None, disposition, flags, None)
os.rmdir('spam')
>>> print(GetFinalPathNameByHandle(h, 0))
\\?\C:\$Extend\$Deleted\004E00000000632F70819337
FAT filesystems do not support this capability, and may never support it, so the problem hasn't gone away completely. |