This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Eugene Viktorov, SilentGhost, eryksun, georg.brandl, martin.panter
Date 2016-02-19.04:54:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> Does the unlink() work on Windows?

Yes. O_TEMPORARY opens the file with FILE_SHARE_DELETE, so unlink won't raise an error. 

Opening a file creates and returns a handle for a kernel File object that references the underlying file/link/stream control block in the file system. There may be multiple open File objects from separate NtCreateFile and NtOpenFile system calls, but they all reference a common file control block. Deleting a file requires a File handle, which is used to set the delete disposition in the control block. When all references (handle and pointer) to all File objects that reference the file are closed, the file is unlinked if the delete disposition is set.

The way delete-on-close works is to set a flag in the File object that causes the delete disposition to be automatically set when the File object is closed. However, any File handle that references the file can be used to set or unset this disposition if it has DELETE access. So it's harmless to manually call DeleteFile on the file (i.e. NtOpenFile and NtSetInformationFile to set the delete disposition) beforehand.
Date User Action Args
2016-02-19 04:54:16eryksunsetrecipients: + eryksun, georg.brandl, SilentGhost, martin.panter, Eugene Viktorov
2016-02-19 04:54:15eryksunsetmessageid: <>
2016-02-19 04:54:15eryksunlinkissue26385 messages
2016-02-19 04:54:15eryksuncreate