Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions include/boost/filesystem/directory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ void recursive_directory_iterator_increment(recursive_directory_iterator& it, sy
BOOST_FILESYSTEM_DECL
void recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec);

enum class directory_entry_update_mask : unsigned int
{
none = 0u,
symlink_status = 1u,
status = 1u << 1u,
all = 3u
};

BOOST_BITMASK(directory_entry_update_mask)

} // namespace detail

//--------------------------------------------------------------------------------------//
Expand Down Expand Up @@ -199,7 +209,7 @@ class directory_entry
directory_entry(boost::filesystem::path const& p, system::error_code& ec) :
m_path(p)
{
refresh_impl(&ec);
refresh_impl(update_mask::all, &ec);
if (ec)
m_path.clear();
}
Expand Down Expand Up @@ -327,7 +337,7 @@ class directory_entry
void assign(boost::filesystem::path const& p, system::error_code& ec)
{
m_path = p;
refresh_impl(&ec);
refresh_impl(update_mask::all, &ec);
}

/*!
Expand All @@ -345,7 +355,7 @@ class directory_entry
void assign(boost::filesystem::path&& p, system::error_code& ec)
{
m_path = static_cast< boost::filesystem::path&& >(p);
refresh_impl(&ec);
refresh_impl(update_mask::all, &ec);
}
#endif
#if BOOST_FILESYSTEM_VERSION < 4 || defined(BOOST_FILESYSTEM_DOXYGEN)
Expand Down Expand Up @@ -430,7 +440,7 @@ class directory_entry
void replace_filename(boost::filesystem::path const& p, system::error_code& ec)
{
m_path.replace_filename(p);
refresh_impl(&ec);
refresh_impl(update_mask::all, &ec);
}
#endif
#if BOOST_FILESYSTEM_VERSION < 4 || defined(BOOST_FILESYSTEM_DOXYGEN)
Expand Down Expand Up @@ -491,17 +501,17 @@ class directory_entry
*
* \param ec Error code returned in case of failure.
*/
void refresh(system::error_code& ec) noexcept { refresh_impl(&ec); }
void refresh(system::error_code& ec) noexcept { refresh_impl(update_mask::all, &ec); }

/*! \overload */
void refresh() { refresh_impl(); }
void refresh() { refresh_impl(update_mask::all); }

/*!
* \brief Returns the file status.
*
* \effects
* For the cached file status `m_status`, if `!status_known(m_status)`, calls `refresh(ec)`. Then returns
* `m_status`.
* For the cached file status `m_status`, if `!status_known(m_status)`, refreshes the cache to update it.
* Then returns `m_status`.
*
* \note The implementation does not query the filesystem after the file status has been cached.
* Filesystem changes after the file status has been cached will not be reflected in the result.
Expand All @@ -515,24 +525,24 @@ class directory_entry
ec.clear();

if (!filesystem::status_known(m_status))
refresh_impl(&ec);
refresh_impl(update_mask::all, &ec);
return m_status;
}

/*! \overload */
file_status status() const
{
if (!filesystem::status_known(m_status))
refresh_impl();
refresh_impl(update_mask::all);
return m_status;
}

/*!
* \brief Returns the symlink file status.
*
* \effects
* For the cached symlink file status `m_symlink_status`, if `!status_known(m_symlink_status)`, calls
* `refresh(ec)`. Then returns `m_symlink_status`.
* For the cached symlink file status `m_symlink_status`, if `!status_known(m_symlink_status)`, refreshes
* the cache to update it. Then returns `m_symlink_status`.
*
* \note The implementation does not query the filesystem after the symlink file status has been cached.
* Filesystem changes after the symlink file status has been cached will not be reflected in the result.
Expand All @@ -546,15 +556,15 @@ class directory_entry
ec.clear();

if (!filesystem::status_known(m_symlink_status))
refresh_impl(&ec);
refresh_impl(update_mask::symlink_status, &ec);
return m_symlink_status;
}

/*! \overload */
file_status symlink_status() const
{
if (!filesystem::status_known(m_symlink_status))
refresh_impl();
refresh_impl(update_mask::symlink_status);
return m_symlink_status;
}

Expand All @@ -577,15 +587,15 @@ class directory_entry
ec.clear();

if (!filesystem::type_present(m_status))
refresh_impl(&ec);
refresh_impl(update_mask::all, &ec);
return m_status.type();
}

/*! \overload */
filesystem::file_type file_type() const
{
if (!filesystem::type_present(m_status))
refresh_impl();
refresh_impl(update_mask::all);
return m_status.type();
}

Expand All @@ -608,15 +618,15 @@ class directory_entry
ec.clear();

if (!filesystem::type_present(m_symlink_status))
refresh_impl(&ec);
refresh_impl(update_mask::symlink_status, &ec);
return m_symlink_status.type();
}

/*! \overload */
filesystem::file_type symlink_file_type() const
{
if (!filesystem::type_present(m_symlink_status))
refresh_impl();
refresh_impl(update_mask::symlink_status);
return m_symlink_status.type();
}

Expand Down Expand Up @@ -942,7 +952,9 @@ class directory_entry

#if !defined(BOOST_FILESYSTEM_DOXYGEN)
private:
BOOST_FILESYSTEM_DECL void refresh_impl(system::error_code* ec = nullptr) const;
using update_mask = detail::directory_entry_update_mask;

BOOST_FILESYSTEM_DECL void refresh_impl(update_mask mask, system::error_code* ec = nullptr) const;

void assign_with_status(boost::filesystem::path&& p, file_status st, file_status symlink_st)
{
Expand Down Expand Up @@ -978,15 +990,15 @@ inline directory_entry::directory_entry(boost::filesystem::path const& p) :
m_path(p)
{
#if BOOST_FILESYSTEM_VERSION >= 4
refresh_impl();
refresh_impl(update_mask::all);
#endif
}

inline void directory_entry::assign(boost::filesystem::path&& p)
{
m_path = static_cast< boost::filesystem::path&& >(p);
#if BOOST_FILESYSTEM_VERSION >= 4
refresh_impl();
refresh_impl(update_mask::all);
#else
m_status = file_status();
m_symlink_status = file_status();
Expand All @@ -997,7 +1009,7 @@ inline void directory_entry::assign(boost::filesystem::path const& p)
{
m_path = p;
#if BOOST_FILESYSTEM_VERSION >= 4
refresh_impl();
refresh_impl(update_mask::all);
#else
m_status = file_status();
m_symlink_status = file_status();
Expand All @@ -1008,7 +1020,7 @@ inline void directory_entry::replace_filename(boost::filesystem::path const& p)
{
m_path.replace_filename(p);
#if BOOST_FILESYSTEM_VERSION >= 4
refresh_impl();
refresh_impl(update_mask::all);
#else
m_status = file_status();
m_symlink_status = file_status();
Expand Down
11 changes: 8 additions & 3 deletions src/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ namespace filesystem {
// //
//--------------------------------------------------------------------------------------//

BOOST_FILESYSTEM_DECL void directory_entry::refresh_impl(system::error_code* ec) const
BOOST_FILESYSTEM_DECL void directory_entry::refresh_impl(
directory_entry::update_mask mask,
system::error_code* ec) const
{
m_status = filesystem::file_status();
const bool update_status = (mask & update_mask::status) != update_mask::none;

if (update_status)
m_status = filesystem::file_status();
m_symlink_status = filesystem::file_status();

m_symlink_status = detail::symlink_status(m_path, ec);
Expand All @@ -116,7 +121,7 @@ BOOST_FILESYSTEM_DECL void directory_entry::refresh_impl(system::error_code* ec)
// Also works if symlink_status fails - set m_status to status_error as well
m_status = m_symlink_status;
}
else
else if (update_status)
{
m_status = detail::status(m_path, ec);
}
Expand Down
Loading