directory_entry::symlink_status(error_code&) and a number of other member functions report errors for dangling symlinks.
The following test program:
#include <boost/detail/lightweight_test_report.hpp>
#include <boost/filesystem.hpp>
int test_main(int, char*[])
{
namespace fs = boost::filesystem;
using boost::system::error_code;
fs::path dir = fs::temp_directory_path() / "dirent_bug";
fs::remove_all(dir);
fs::create_directories(dir);
fs::create_symlink("nonexistent", dir / "dangling");
fs::directory_entry entry(dir / "dangling");
error_code ec;
fs::file_type t = entry.symlink_status(ec).type();
BOOST_TEST_EQ(t, fs::symlink_file);
BOOST_TEST(!ec);
fs::remove_all(dir);
return ::boost::report_errors();
}
produces the following output:
Clang version 21.0.0 (clang-2100.1.1.101), __GXX_EXPERIMENTAL_CXX0X__ defined
libc++ version 210106
Mac OS
Boost version 1.92.0
Command line: ./libs/filesystem/bug/bin/bug
libs/filesystem/bug/bug.cpp(21): test '!ec' failed in function 'int test_main(int, char **)'
1 error detected.
The reason is that directory_entry::refresh_impl propagates errors from stat calls regardless of where it's called from. In v4, this also affects the constructor overload that takes an error code, since the constructor updates the cache.
directory_entry::symlink_status(error_code&)and a number of other member functions report errors for dangling symlinks.The following test program:
produces the following output:
The reason is that
directory_entry::refresh_implpropagates errors fromstatcalls regardless of where it's called from. In v4, this also affects the constructor overload that takes an error code, since the constructor updates the cache.