On 22/06/2012 7:23 PM, robert.van.herk@serioustoys.com wrote:
Is there any reason that you call DeleteFile() on a still being opened file?
That's the whole point of this test. The observed behavior is that you can pass a filename to MsiRecordSetStream, successfully delete the file, and keep on using the stream.
I think DeleteFile on a opened file is officially allowed in Windows. Although the MS documentation is vague:
<QUOTE> The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file.
The DeleteFile function marks a file for deletion on close. Therefore, the file deletion does not occur until the last handle to the file is closed. Subsequent calls to CreateFile to open the file fail with ERROR_ACCESS_DENIED.
</QUOTE>
The first statement is true under the DOS-based Windows systems - DeleteFile fails with ERROR_ACCESS_DENIED when that file has one or more open file handles.
The second statement is true under the NT Windows systems - DeleteFile will fail with ERROR_SHARING_VIOLATION if at least one handle to it isn't opened with FILE_SHARE_DELETE, and ERROR_ACCESS_DENIED if it has a memory mapping.
Results from the attached test under Windows 7 x64:
Testing with no sharing, same process and no file mapping DeleteFile: Failed : 00000020 Done
Testing with FILE_SHARE_DELETE, same process and no file mapping DeleteFile: OK Done
Testing with no sharing, separate process and no file mapping DeleteFile: Failed : 00000020 Done
Testing with FILE_SHARE_DELETE, separate process and no file mapping DeleteFile: OK Done
Testing with no sharing, same process and file mapping DeleteFile: Failed : 00000020 Done
Testing with FILE_SHARE_DELETE, same process and file mapping DeleteFile: Failed : 00000005 Done
Testing with no sharing, separate process and file mapping DeleteFile: Failed : 00000020 Done
Testing with FILE_SHARE_DELETE, separate process and file mapping DeleteFile: Failed : 00000005 Done
Results from the attached test under Windows 98 SE:
Testing with no sharing, same process and no file mapping DeleteFile: Failed : 00000005 Done
Testing with FILE_SHARE_DELETE, same process and no file mapping CreateFile failed : 00000057 DeleteFile: OK Done
Testing with no sharing, separate process and no file mapping DeleteFile: Failed : 00000005 Done
Testing with FILE_SHARE_DELETE, separate process and no file mapping CreateFile failed : 00000057 DeleteFile: OK Done
Testing with no sharing, same process and file mapping DeleteFile: Failed : 00000005 Done
Testing with FILE_SHARE_DELETE, same process and file mapping CreateFile failed : 00000057 DeleteFile: OK Done
Testing with no sharing, separate process and file mapping DeleteFile: Failed : 00000005 Done
Testing with FILE_SHARE_DELETE, separate process and file mapping CreateFile failed : 00000057 DeleteFile: OK Done