[New-bugs-announce] [issue15244] Support for opening files with FILE_SHARE_DELETE on Windows

Richard Oudkerk report at bugs.python.org
Tue Jul 3 21:14:54 CEST 2012


New submission from Richard Oudkerk <shibturn at gmail.com>:

On Unix, files (unless specifically locked) can be renamed and deleted while file descriptors for the file remain open.  The file descriptors remain valid even after deletion of the file.

On Windows this is not possible for files opened using io.open() or os.open().  However, by using the FILE_SHARE_DELETE flag in CreateFile() one can get Unix-like behaviour.

Unfortunately, FILE_SHARE_DELETE is only available through the Win32 API, not through the CRT.  Also, Issue #14243 concerns the fact that on Windows temporary files cannot be reopened unless one uses the FILE_SHARE_DELETE flag.  One can only reopen a file by using a share mode that is at least as permissive as the share mode for all the currently open handles.

The attached patch adds a module "share" (bad name?) with functions share.open() and share.os_open() which act as substitutes for io.open() and os.open().  These by default use FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE as the share mode.  (io.open() and os.open() use FILE_SHARE_READ | FILE_SHARE_WRITE instead.)

To run the full regression test suite with builtins.open(), io.open() and os.open() monkey patched to use these replacements you can do

    python -m test.test_share --regrtest

Nothing seems to break.

----------
components: Library (Lib)
files: share.patch
keywords: patch
messages: 164616
nosy: sbt
priority: normal
severity: normal
stage: patch review
status: open
title: Support for opening files with FILE_SHARE_DELETE on Windows
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file26249/share.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15244>
_______________________________________


More information about the New-bugs-announce mailing list