Skip to content

Commit 7403ffc

Browse files
committed
Added support for POSIX semantics for file removal on Windows.
Windows 10 1709 and later support POSIX semantics for removing files, which means the file name is removed from the filesystem namespace as soon as the file is marked for deletion. This makes opening the file afterwards impossible, and allows creating a new file with the same name, even if the deleted file is still open and in use. The implementation uses runtime detection of the feature in the OS. We are also using two more implementations for file removal: one that employs the more recent FILE_DISPOSITION_FLAG_IGNORE_READONLY_ATTRIBUTE flag (available since Windows 10 1809), and FILE_DISPOSITION_INFO structure (supported since Windows Vista). The former allows to optimize removal of read-only files, and the latter allows to make file deletion atomic (i.e. not prone to failure if the file is replaced on the filesystem while the operation is executing). The implementation is chosen in runtime, depending on which one succeeds removing a file. Also, added support for deleting read-only directories, in addition to non-directory files, and simplified code a little. Closes boostorg#216.
1 parent 97722a3 commit 7403ffc

File tree

3 files changed

+360
-172
lines changed

3 files changed

+360
-172
lines changed

doc/release_history.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ <h2>1.79.0</h2>
4444
<li><b>v3:</b> <code>path::replace_extension</code> now works in terms of <b>v3</b> definition of <code>path::extension</code> rather than <b>v4</b>.</li>
4545
<li>Fixed compilation of path appending and concatenation operators with arguments of types convertible to <code>path</code> or compatible string type. (<a href="https://github.com/boostorg/filesystem/issues/223">#223</a>)</li>
4646
<li>On POSIX systems that support <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html"><code>fdopendir</code></a> and <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html"><code>O_NOFOLLOW</code></a> and on Windows, <code>remove_all</code> is now protected against <a href="https://www.cve.org/CVERecord?id=CVE-2022-21658">CVE-2022-21658</a>. The vulnerability is a race condition that allows a third party process to replace a directory that is being concurrently processed by <code>remove_all</code> with a directory symlink and cause <code>remove_all</code> to follow the symlink and remove files in the linked directory instead of removing the symlink itself. (<a href="https://github.com/boostorg/filesystem/issues/224">#224</a>)</li>
47+
<li>On Windows, in <code>remove</code> and <code>remove_all</code> implementation, use POSIX semantics for file removal, when supported by the OS (Windows 10 1709 and later). When POSIX semantics is supported, the file name is removed from the filesystem namespace as soon as the file is marked for deletion, even if it is still open and in use. With legacy Windows semantics, the file name remains present in the the filesystem namespace until the last file handle to the file is closed, which allows the file marked for deletion to be opened and prevents creating new files with the same name. (<a href="https://github.com/boostorg/filesystem/issues/216">#216</a>)</li>
48+
<li>On Windows, <code>remove</code> and <code>remove_all</code> now support deleting read-only directories. Support for removing read-only non-directory files was added previously.</li>
4749
<li>On Windows, <code>directory_iterator</code> internal implementation has been reworked to better utilize modern Windows APIs, which may improve performance while handling symlinks.</li>
4850
<li>On Windows, initialize internal WinAPI function pointers early, if possible, to allow Boost.Filesystem operations to be invoked in global constructors. This is only supported on MSVC, GCC, Clang and compatible compilers.</li>
4951
<li>On Windows, <code>resize_file</code> should no longer fail with an error if the file to be resized is opened.</li>

0 commit comments

Comments
 (0)