Skip to content

Fix unprovoked symlink errors in directory_entry - #353

Merged
Lastique merged 5 commits into
boostorg:developfrom
stm-ableton:fix-directory-entry-symlink-errors
Sep 2, 2026
Merged

Fix unprovoked symlink errors in directory_entry#353
Lastique merged 5 commits into
boostorg:developfrom
stm-ableton:fix-directory-entry-symlink-errors

Conversation

@stm-ableton

Copy link
Copy Markdown
Contributor

Closes #352.

Also adds tests exercising directory_entry.

@stm-ableton
stm-ableton marked this pull request as draft August 3, 2026 09:53
@stm-ableton
stm-ableton marked this pull request as ready for review August 3, 2026 12:27
@Lastique

Lastique commented Aug 3, 2026

Copy link
Copy Markdown
Member

I'd like to let you know that there is a massive change to library headers coming soon, that will likely make PRs against headers non-applicable. You may want to hold off the work on this.

@stm-ableton
stm-ableton marked this pull request as draft August 3, 2026 14:59
@stm-ableton

Copy link
Copy Markdown
Contributor Author

@Lastique Thank you for the heads up. I've converted to draft for now.

@stm-ableton
stm-ableton force-pushed the fix-directory-entry-symlink-errors branch from 5a366ca to 15dbc1d Compare August 23, 2026 06:22
Since
boostorg@d508d49,
a number of functions in directory_entry's public interface call
directory_entry::refresh_impl, which updates the cached file status
comprehensively. On POSIX systems, for example, both lstat and stat are
called for symlinks, and stat errors are reported to the caller. As a
result, e.g. checking the status of a symlink with symlink_status
produces an error if the symlink target is gone or if access to it is
denied. In v4, this also affects the constructor overload that takes an
error_code, i.e. constructing a directory_entry with a path to a broken
symlink produces an error.

Add a parameter to refresh_impl allowing to configure what the caller is
interested in, thus avoiding false positives.
@stm-ableton
stm-ableton force-pushed the fix-directory-entry-symlink-errors branch from 15dbc1d to 76bf91a Compare August 23, 2026 09:04
@stm-ableton
stm-ableton marked this pull request as ready for review August 24, 2026 07:33
@stm-ableton

Copy link
Copy Markdown
Contributor Author

I've rebased around 2466fc1 (I assumed this was the change to library headers).

Comment thread include/boost/filesystem/directory.hpp Outdated
BOOST_FILESYSTEM_DECL void refresh_impl(
system::error_code* ec = nullptr,
refresh_mode mode = refresh_mode::follow_lenient) const;
void refresh_impl(refresh_mode mode) const { refresh_impl(nullptr, mode); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather there was a single refresh_impl, with the first argument of refresh_mode/update_mask (with no default) and the second one of error_core* (with nullptr default). This follows the existing convention.

Comment thread include/boost/filesystem/directory.hpp Outdated
{
no_follow,
follow,
follow_lenient

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure lenient is needed. In C++ standard, std::filesystem::directory_entry constructor and assign are specified to call refresh, i.e. those APIs are expected to fail if status fails. Other APIs that rely on status, obviously, should also fail if status fails. The only APIs that only require symlink status are symlink_status and is_symlink, and those APIs may not update the cached status.

I think, a better way to do this is change refresh_mode to update_mask, which would be a bit mask of which statuses to update (update_status, update_symlink_status). symlink_status and is_symlink would only specify update_symlink_status and every other API would specify both.

stm added 4 commits September 1, 2026 14:41
Fix unprovoked symlink errors in directory_entry

Since
boostorg@d508d49,
a number of functions in directory_entry's public interface call
directory_entry::refresh_impl, which updates the cached file status.
This happens comprehensively; on POSIX systems, for example, both lstat
and stat are called for symlinks, and stat errors are reported to the
caller. As a result, e.g. checking the status of a symlink with
symlink_status produces an error if the symlink target is gone or if
access to it is denied.

Add a parameter to refresh_impl allowing to configure what the caller is
interested in, thus avoiding false positives.

Note that only symlink_status, symlink_file_type and the APIs
implemented in terms of them skip the m_status update. The other APIs
still update both statuses, and report errors accordingly.
Get rid of the refresh_impl overload, makes sure error_code is the last
parameter.
Introduce enumerator to use as a shorthand
@stm-ableton

Copy link
Copy Markdown
Contributor Author

@Lastique Thanks. I pushed some fixups, in separate commits to make them hopefully easier to review.

@Lastique
Lastique merged commit 5ae68b4 into boostorg:develop Sep 2, 2026
62 checks passed
@Lastique

Lastique commented Sep 2, 2026

Copy link
Copy Markdown
Member

Thanks.

Lastique added a commit that referenced this pull request Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

directory_entry reports errors for dangling symlinks when it shouldn't

2 participants