You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add dir_entry::refresh and file type observers. Use them in recursive dir_it.
This commit changes behavior of directory_entry constructors and modifiers
that change the stored path in v4: the methods will now automatically query
the filesystem for the file status instead of leaving the cached data
default-initialized. This means that the paths passed to directory_entry
must be valid, otherwise an error will be returned. Filesystem querying
is implemented in the new directory_entry::refresh methods.
The constructors and modifiers that accepted file_status arguments are
now removed in v4. The cached file statuses are an implementation detail,
and eventually we may want to add more cached data, as we add more observers
to directory_entry.
Also added a few file type observers to directory_entry. These observers
allow to avoid querying the filesystem if the full file status is not cached
but the file type is (i.e. when permissions are not cached). This is the case
with readdir-based implementation of directory_iterator, if the underlying
C library supports dirent::d_type field.
recursive_directory_iterator has been updated to use the added file type
observers instead of querying the full status. This may improve performance
of directory iteration.
Closes#288.
<p>A <code>directory_entry</code> object stores a <code>path object</code>,
2581
-
a <code>file_status</code> object for non-symbolic link status, and a <code>file_status</code> object for symbolic link status. The <code>file_status</code> objects act as value caches.</p>
2605
+
<p>A <code>directory_entry</code> object stores a <code>path</code> object,
2606
+
as well as some amount of cached information about the file identified by the path.
2607
+
Currently, the cached information includes a <code>file_status</code> object for non-symbolic
2608
+
link status and a <code>file_status</code> object for symbolic link status.</p>
2582
2609
<blockquote>
2583
-
<p>[<i>Note:</i> Because <code>status()</code>on a pathname may be a relatively expensive operation,
2610
+
<p>[<i>Note:</i> Because <code>status()</code>on a pathname may be a relatively expensive operation,
2584
2611
some operating systems provide status information as a byproduct of directory
2585
2612
iteration. Caching such status information can result is significant time savings. Cached and
2586
2613
non-cached results may differ in the presence of file system races. <i>—end note</i>]</p>
<p><b>v3:</b> Initializes <code>m_path</code> from <code>p</code> and default-constructs <code>m_status</code> and <code>m_symlink_status</code>.</p>
2655
+
<p>[<i>Note:</i> The cached file statuses will be updated when queried by the caller or by an explicit call to <code>refresh</code>. <i>—end note</i>]</p>
2656
+
<p><b>v4:</b> Initializes <code>m_path</code> from <code>p</code> and calls <code>refresh()</code> or <code>refresh(ec)</code>, respectively.</p>
2657
+
<p><i>Postcondition:</i><code>path() == p</code> if no error occurs, otherwise <code>path().empty() == true</code>.</p>
<p><b>v3:</b> Assigns <code>p</code> to <code>m_path</code> and <code>file_status()</code> to <code>m_status</code> and <code>m_symlink_status</code>.</p>
2688
+
<p>[<i>Note:</i> The cached file statuses will be updated when queried by the caller or by an explicit call to <code>refresh</code>. <i>—end note</i>]</p>
2689
+
<p><b>v4:</b> Assigns <code>p</code> to <code>m_path</code> and calls <code>refresh()</code> or <code>refresh(ec)</code>, respectively. If an error
2690
+
occurs, the value of the cached data is unspecified.</p>
<p><b>v3:</b> Calls <code>m_path.replace_filename(p)</code> and assigns <code>file_status()</code> to <code>m_status</code> and <code>m_symlink_status</code>.</p>
2719
+
<p>[<i>Note:</i> The cached file statuses will be updated when queried by the caller or by an explicit call to <code>refresh</code>. <i>—end note</i>]</p>
2720
+
<p><b>v4:</b> Calls <code>m_path.replace_filename(p)</code> and then <code>refresh()</code> or <code>refresh(ec)</code>, respectively. If an error
2721
+
occurs, the value of the cached data is unspecified.</p>
<p><i>Effects:</i><b>v3:</b> Calls <code>m_path.replace_filename(p)</code> and assigns <code>st</code> to <code>m_status</code> and <code>symlink_st</code>
2726
+
to <code>m_symlink_status</code>.</p>
2727
+
</blockquote>
2728
+
<pre>void refresh();
2729
+
void refresh(system::error_code& ec);</pre>
2730
+
<blockquote>
2731
+
<p><i>Effects:</i> Updates any cached data by querying the filesystem about the file identified by <code>m_path</code>. If an error occurs,
Copy file name to clipboardExpand all lines: doc/release_history.html
+5
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,11 @@
41
41
42
42
<h2>1.83.0</h2>
43
43
<ul>
44
+
<li>Added <code>directory_entry::refresh</code> method that updates internal cached file statuses for the directory entry identified by path.</li>
45
+
<li><b>v4:</b><code>directory_entry</code> constructors and modifiers that initialize or modify the path now automatically call <code>refresh</code>. This may result in errors that were not indicated before and in <b>v3</b>, if querying the filesystem for file statuses fails (e.g. if the file does not exist). This new behavior is similar to std::filesystem.</li>
46
+
<li><b>v4:</b><code>directory_entry</code> constructors and methods taking <code>file_status</code> parameters are removed. Users are recommended to remove these arguments and rely on <code>directory_entry</code> calling <code>refresh</code> internally.</li>
47
+
<li>Added <code>directory_entry</code> member methods for checking the file type of the file, similar to std::filesystem.</li>
48
+
<li><code>recursive_directory_iterator</code> is now more likely to reuse information about the file type that is obtained during filesystem iteration. This may improve performance. (<ahref="https://github.com/boostorg/filesystem/issues/288">#288</a>)</li>
44
49
<li>File streams defined in <code>boost/filesystem/fstream.hpp</code> are now movable, if the standard library file streams are. (<ahref="https://github.com/boostorg/filesystem/issues/280">#280</a>)</li>
45
50
<li>Generic <code>path</code> comparison operators are now more restricted to avoid potential ambiguities when user's code contains a <code>using namespace boost::filesystem;</code> directive. (<ahref="https://github.com/boostorg/filesystem/issues/285">#285</a>)</li>
46
51
<li>Fixed potential overload resolution ambiguity in users' code, where <code>path</code> constructors from iterators could interfere with function overloads taking a <code>std::initializer_list</code> argument. (<ahref="https://github.com/boostorg/filesystem/issues/287">#287</a>)</li>
Copy file name to clipboardExpand all lines: doc/v4.html
+4-1
Original file line number
Diff line number
Diff line change
@@ -54,10 +54,13 @@ <h2>Breaking changes</h2>
54
54
<li><ahref="reference.html#path-appends"><code>path</code> appends</a> consider root name and root directory of the appended path. If the appended path is absolute, or root name is present and differs from the source path, the resulting path is equivalent to the appended path. If root directory is present, the result is the root directory and relative path rebased on top of the root name of the source path. Otherwise, the behavior is similar to v3. This behavior is similar to C++17 std::filesystem.</li>
55
55
<li><code>path</code> no longer supports construction, assignment or appending from containers of characters. Use string types or iterators as the source for these opereations instead.</li>
56
56
<li><ahref="reference.html#path-remove_filename"><code>path::remove_filename</code></a> preserves the trailing directory separator, so that <code>path::has_filename</code> returns <code>false</code> after a successful call to <code>path::remove_filename</code>.</li>
57
+
<li><code>directory_entry</code> constructors and modifiers that initialize or modify path of the directory entry automatically call <code>directory_entry::refresh</code> instead of clearing cached file statuses. This means that the file identified by the new path needs to be accessible in the filesystem at the point of the call.</li>
58
+
<li><code>directory_entry</code> constructors and modifiers that accept <code>file_status</code> arguments to initialize cached file statuses are removed. The amount of cached data
59
+
is an implementation detail of <code>directory_entry</code>, and in the future it may not be limited to just file statuses. Users should rely on automatic refreshes of the cached data.</li>
0 commit comments