> I'm afraid that the problem doesn't lie in the unlink: DeleteFile
> succeeds. The problem is that the file is only marked for delete
> until such time as the last SHARE_DELETE handle on it is closed.
Then we shouldn't use DeleteFile in the first place to delete the file,
but instead CreateFile, with DELETE access (and FILE_SHARE_DELETE
sharing). If that fails, we need to move the file to the bin
(see unlink_nt for details).
> Making os.unlink on Windows more robust may be a good
> idea, but it's not going to help this issue. See my test-case.py
> on an earlier message for reproduction:
It certainly will help this case also. It would detect that the file is
still open, and move it into the trash bin.