Skip to content

Commit 18a8a34

Browse files
committed
Added support for removing read-only files on Windows.
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. As a side effect, we were able to remove an implementation detail value from the file_type enum that was used by the old remove() implementation. 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. Also, corrected mklink /J argument in tests. The command accepts /j (lowercase) to the same effect, but the formal help lists /J (uppercase) to create junctions. Reported in #216.
1 parent 46c74a2 commit 18a8a34

File tree

7 files changed

+453
-131
lines changed

7 files changed

+453
-131
lines changed

doc/release_history.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ <h2>1.78.0</h2>
4949
<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>
5050
<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>
5151
<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>
52+
<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>
5253
<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>
5354
</ul>
5455

include/boost/filesystem/file_status.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ enum file_type
4646
fifo_file,
4747
socket_file,
4848
reparse_file, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
49-
type_unknown, // file does exist, but isn't one of the above types or
49+
type_unknown // file does exist, but isn't one of the above types or
5050
// we don't have strong enough permission to find its type
51-
52-
_detail_directory_symlink // internal use only; never exposed to users
5351
};
5452

5553
//--------------------------------------------------------------------------------------//

0 commit comments

Comments
 (0)