diff --git a/include/boost/filesystem/path.hpp b/include/boost/filesystem/path.hpp index 299d528..7ae4d2f 100644 --- a/include/boost/filesystem/path.hpp +++ b/include/boost/filesystem/path.hpp @@ -359,6 +359,7 @@ namespace filesystem ; // change slashes to backslashes # endif path& remove_filename(); + path& remove_trailing_separator(); path& replace_extension(const path& new_extension = path()); void swap(path& rhs) { m_pathname.swap(rhs.m_pathname); } diff --git a/src/operations.cpp b/src/operations.cpp index fad4070..8e8ae28 100644 --- a/src/operations.cpp +++ b/src/operations.cpp @@ -1798,10 +1798,9 @@ namespace detail return path(); } - buf.pop_back(); - - path p(buf.begin(), buf.end()); - + path p(&*buf.begin()); // ticket #10388; note C++03 vector must be contiguous + p.remove_trailing_separator(); // remove trailing backslash + if ((ec&&!is_directory(p, *ec))||(!ec&&!is_directory(p))) { ::SetLastError(ENOTDIR); diff --git a/src/path.cpp b/src/path.cpp index 0bb70a1..df8d8dd 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -254,6 +254,13 @@ namespace filesystem return *this; } + path& path::remove_trailing_separator() + { + if (!m_pathname.empty() && is_separator(m_pathname[m_pathname.size() - 1])) + m_pathname.erase(m_pathname.size() - 1); + return *this; + } + path& path::replace_extension(const path& new_extension) { // erase existing extension, including the dot, if any