From 835bcd3c13697cbd7fc3d8574fd07475eeada398 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Fri, 29 Jan 2016 12:24:58 +0200 Subject: [PATCH 1/2] Add a new method called symlink_type to directory_entry --- include/boost/filesystem/operations.hpp | 8 ++++++++ src/operations.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/include/boost/filesystem/operations.hpp b/include/boost/filesystem/operations.hpp index 47bc0747..7ee59113 100644 --- a/include/boost/filesystem/operations.hpp +++ b/include/boost/filesystem/operations.hpp @@ -813,6 +813,13 @@ class BOOST_FILESYSTEM_DECL directory_entry file_status symlink_status() const {return m_get_symlink_status();} file_status symlink_status(system::error_code& ec) const BOOST_NOEXCEPT {return m_get_symlink_status(&ec); } + // Return the same value as symlink_status().type(), but can be optimized in + // some cases avoiding a system call. E.g. on Linux the type is known from when + // iterating a directory, but the mode is not. Thus symlink_status causes a lstat + // that can be omitted if the filesystem supports it with symlink_type. + file_type symlink_type() const {return m_get_symlink_type();} + file_type symlink_type(system::error_code& ec) const BOOST_NOEXCEPT + {return m_get_symlink_type(&ec); } bool operator==(const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path == rhs.m_path; } bool operator!=(const directory_entry& rhs) const BOOST_NOEXCEPT {return m_path != rhs.m_path;} @@ -828,6 +835,7 @@ class BOOST_FILESYSTEM_DECL directory_entry file_status m_get_status(system::error_code* ec=0) const; file_status m_get_symlink_status(system::error_code* ec=0) const; + file_type m_get_symlink_type(system::error_code* ec=0) const; }; // directory_entry //--------------------------------------------------------------------------------------// diff --git a/src/operations.cpp b/src/operations.cpp index f34b0761..d0d9b577 100644 --- a/src/operations.cpp +++ b/src/operations.cpp @@ -1963,6 +1963,15 @@ namespace detail return m_symlink_status; } + file_type + directory_entry::m_get_symlink_type(system::error_code* ec) const + { + if (!type_present(m_symlink_status)) + m_symlink_status = detail::symlink_status(m_path, ec); + else if (ec != 0) ec->clear(); + return m_symlink_status.type(); + } + // dispatch directory_entry supplied here rather than in // , thus avoiding header circularity. // test cases are in operations_unit_test.cpp From 68ce91f70e23aa07d3c5bd2ec1fddaedaaaf1e6e Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Fri, 29 Jan 2016 13:26:59 +0200 Subject: [PATCH 2/2] reference.html add docs for symlink_type --- doc/reference.html | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/reference.html b/doc/reference.html index 31dfe037..0fcde0d4 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -2490,6 +2490,8 @@ file_status status(system::error_code& ec) const; file_status symlink_status() const; file_status symlink_status(system::error_code& ec) const; + file_type symlink_type() const; + file_type symlink_type(system::error_code& ec) const; bool operator< (const directory_entry& rhs); bool operator==(const directory_entry& rhs); @@ -2649,7 +2651,21 @@

Returns: m_symlink_status

Throws: As specified in Error reporting.

+ +
file_type  symlink_type() const;
+file_type  symlink_type(system::error_code& ec) const;
+
+

+ Effects: As if,

+
+
if ( !type_present( m_symlink_status ) )
+{
+  m_symlink_status = symlink_status(m_path[, ec]);
+}
+
+

Returns: m_symlink_status.type()

+

Throws: As specified in Error reporting.

bool operator==(const directory_entry& rhs);
@@ -4270,4 +4286,4 @@ 01 December 2015

- \ No newline at end of file +