Skip to content

Commit

Permalink
Added support for removing read-only files on Windows.
Browse files Browse the repository at this point in the history
Reworked remove() operation to separate POSIX and Windows implementations.
On Windows, if the file to be removed is read-only, try to reset the read-only
attribute before deleting the file. If deleting fails (other than because the
file is already deleted), try to restore the read-only attribute.

Added a test for remove() on a read-only file on Windows. Also added tests
for remove_all(), including for cases with symlinks, hardlinks and read-only
files.

Closes #216.
  • Loading branch information
Lastique committed Nov 17, 2021
1 parent 46c74a2 commit 1e50808
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 128 deletions.
1 change: 1 addition & 0 deletions doc/release_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2>1.78.0</h2>
<li>Optimized overloads of <code>path::assign</code>, <code>path::append</code>, <code>path::concat</code> and the corresponding operators to avoid unnecessary path copying and reduce the amount of code redundancy.</li>
<li>On POSIX systems, fixed <code>absolute(p, base)</code> returning a path with root name <code>base.root_name()</code> if <code>p</code> starts with a root directory. In such a case <code>p</code> is already an absolute path and should be returned as is.</li>
<li><code>create_directories</code> no longer reports an error if the input path consists entirely of dot (".") and dot-dot ("..") elements. The implementation is no longer using recursion internally and therefore is better protected from stack overflow on extremely long paths.</li>
<li>On Windows, <code>remove</code> now supports deleting read-only files. The operation will attempt to reset the read-only attribute prior to removal. Note that this introduces a possibility of the read-only attribute being left unset, if the operation fails and the original value of the attribute fails to be restored. This also affects <code>remove_all</code>. (<a href="https://github.com/boostorg/filesystem/issues/216">#216</a>)</li>
<li>Fixed a linking error about unresolved references to Boost.ContainerHash functions when user's code includes <code>boost/filesystem/path.hpp</code> but not <code>boost/container_hash/hash.hpp</code> and the compiler is set to preserve unused inline functions. (<a href="https://github.com/boostorg/filesystem/issues/215">#215</a>)</li>
</ul>

Expand Down
4 changes: 1 addition & 3 deletions include/boost/filesystem/file_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ enum file_type
fifo_file,
socket_file,
reparse_file, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
type_unknown, // file does exist, but isn't one of the above types or
type_unknown // file does exist, but isn't one of the above types or
// we don't have strong enough permission to find its type

_detail_directory_symlink // internal use only; never exposed to users
};

//--------------------------------------------------------------------------------------//
Expand Down
Loading

0 comments on commit 1e50808

Please sign in to comment.