refs #90, fixing stuff broken on POSIX side during backend rework.

This commit is contained in:
Steffen Schuemann 2021-01-31 12:03:17 +01:00
parent c96b0059c3
commit a7abc2ad4a

View File

@ -130,12 +130,12 @@
#else
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#ifdef GHC_OS_ANDROID
#include <android/api-level.h>
#if __ANDROID_API__ < 12
@ -281,7 +281,6 @@ template <typename char_type>
constexpr char_type path_helper_base<char_type>::preferred_separator;
#endif
#ifdef GHC_OS_WINDOWS
class path;
namespace detail {
@ -289,7 +288,6 @@ bool has_executable_extension(const path& p);
}
#endif
// 30.10.8 class path
class GHC_FS_API_CLASS path
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE)
@ -518,10 +516,10 @@ private:
friend path canonical(const path& p, std::error_code& ec);
string_type::size_type root_name_length() const noexcept;
void postprocess_path_with_format(format fmt);
void check_long_path();
impl_string_type _path;
#ifdef GHC_OS_WINDOWS
void handle_prefixes();
void check_long_path();
friend bool detail::has_executable_extension(const path& p);
#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH
string_type::size_type _prefixLength{0};
@ -1577,7 +1575,7 @@ GHC_INLINE bool endsWith(const strT& what, const strT& with)
GHC_INLINE void path::check_long_path()
{
#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
if (is_absolute() && _path.length() >= MAX_PATH - 12 && !detail::startsWith(_path, impl_string_type("\\\\?\\"))) {
postprocess_path_with_format(native_format);
}
@ -1679,8 +1677,10 @@ GHC_INLINE bool equals_simple_insensitive(const char* str1, const char* str2)
GHC_INLINE int compare_simple_insensitive(const char* str1, size_t len1, const char* str2, size_t len2)
{
while (len1 > 0 && len2 > 0 && ::tolower((unsigned char)*str1) == ::tolower((unsigned char)*str2)) {
--len1; --len2;
++str1; ++str2;
--len1;
--len2;
++str1;
++str2;
}
if (len1 && len2) {
return *str1 < *str2 ? -1 : 1;
@ -1903,7 +1903,8 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec)
switch (reparseData->ReparseTag) {
case IO_REPARSE_TAG_SYMLINK: {
auto printName = std::wstring(&reparseData->SymbolicLinkReparseBuffer.PathBuffer[reparseData->SymbolicLinkReparseBuffer.PrintNameOffset / sizeof(WCHAR)], reparseData->SymbolicLinkReparseBuffer.PrintNameLength / sizeof(WCHAR));
auto substituteName = std::wstring(&reparseData->SymbolicLinkReparseBuffer.PathBuffer[reparseData->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(WCHAR)], reparseData->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR));
auto substituteName =
std::wstring(&reparseData->SymbolicLinkReparseBuffer.PathBuffer[reparseData->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(WCHAR)], reparseData->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR));
if (detail::endsWith(substituteName, printName) && detail::startsWith(substituteName, std::wstring(L"\\??\\"))) {
result = printName;
}
@ -2167,13 +2168,17 @@ GHC_INLINE path::path() noexcept {}
GHC_INLINE path::path(const path& p)
: _path(p._path)
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
, _prefixLength(p._prefixLength)
#endif
{
}
GHC_INLINE path::path(path&& p) noexcept
: _path(std::move(p._path))
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
, _prefixLength(p._prefixLength)
#endif
{
}
@ -2221,14 +2226,18 @@ GHC_INLINE path::~path() {}
GHC_INLINE path& path::operator=(const path& p)
{
_path = p._path;
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
_prefixLength = p._prefixLength;
#endif
return *this;
}
GHC_INLINE path& path::operator=(path&& p) noexcept
{
_path = std::move(p._path);
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
_prefixLength = p._prefixLength;
#endif
return *this;
}
@ -2268,7 +2277,9 @@ template <>
inline path& path::assign<path>(const path& source)
{
_path = source._path;
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
_prefixLength = source._prefixLength;
#endif
return *this;
}
@ -2445,7 +2456,9 @@ inline path& path::concat(InputIterator first, InputIterator last)
GHC_INLINE void path::clear() noexcept
{
_path.clear();
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
_prefixLength = 0;
#endif
}
GHC_INLINE path& path::make_preferred()
@ -2483,7 +2496,9 @@ GHC_INLINE path& path::replace_extension(const path& replacement)
GHC_INLINE void path::swap(path& rhs) noexcept
{
_path.swap(rhs._path);
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
std::swap(_prefixLength, rhs._prefixLength);
#endif
}
//-----------------------------------------------------------------------------
@ -2579,7 +2594,7 @@ inline std::basic_string<EcharT, traits, Allocator> path::generic_string(const A
}
return result;
#else
return _path:
return detail::fromUtf8<std::basic_string<EcharT, traits, Allocator>>(_path, a);
#endif
}
@ -2590,7 +2605,7 @@ GHC_INLINE std::string path::generic_string() const
#ifdef GHC_OS_WINDOWS
return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
#else
return _path:
return _path;
#endif
}
@ -2618,7 +2633,7 @@ GHC_INLINE std::string path::generic_u8string() const
#ifdef GHC_OS_WINDOWS
return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
#else
return _path:
return _path;
#endif
}
#endif
@ -2717,17 +2732,19 @@ GHC_INLINE int path::compare(const value_type* s) const
//-----------------------------------------------------------------------------
// 30.10.8.4.9, decomposition
#ifdef GHC_OS_WINDOWS
GHC_INLINE void path::handle_prefixes()
{
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
#if defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
_prefixLength = 0;
if (_path.length() >= 6 && _path[2] == '?' && std::toupper(static_cast<unsigned char>(_path[4])) >= 'A' && std::toupper(static_cast<unsigned char>(_path[4])) <= 'Z' && _path[5] == ':') {
if (detail::startsWith(_path, impl_string_type("\\\\?\\")) || detail::startsWith(_path, impl_string_type("\\??\\"))) {
_prefixLength = 4;
}
}
#endif // GHC_OS_WINDOWS
#endif // GHC_WIN_AUTO_PREFIX_LONG_PATH
}
#endif
GHC_INLINE path::string_type::size_type path::root_name_length() const noexcept
{
@ -3005,7 +3022,8 @@ GHC_INLINE path::impl_string_type::const_iterator path::iterator::increment(cons
if (i != _last) {
if (fromStart && i == _first && _prefix > _first) {
i = _prefix;
} else if (*i++ == internal_separator) {
}
else if (*i++ == internal_separator) {
// we can only sit on a slash if it is a network name or a root
if (i != _last && *i == internal_separator) {
if (fromStart && !(i + 1 != _last && *(i + 1) == internal_separator)) {
@ -3187,7 +3205,6 @@ GHC_INLINE bool operator>=(const path& lhs, const path& rhs) noexcept
return lhs.compare(rhs) >= 0;
}
GHC_INLINE path operator/(const path& lhs, const path& rhs)
{
path result(lhs);
@ -3431,7 +3448,6 @@ GHC_INLINE path canonical(const path& p, std::error_code& ec)
result /= target;
continue;
}
}
else {
result /= pe;
@ -3698,7 +3714,8 @@ GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept
std::error_code tmp_ec;
if (is_directory(current, tmp_ec)) {
ec.clear();
} else {
}
else {
return false;
}
}
@ -4515,9 +4532,11 @@ GHC_INLINE uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
break;
}
bool is_symlink_result = iter->is_symlink(ec);
if (ec) return static_cast<uintmax_t>(-1);
if (ec)
return static_cast<uintmax_t>(-1);
bool is_directory_result = iter->is_directory(ec);
if (ec) return static_cast<uintmax_t>(-1);
if (ec)
return static_cast<uintmax_t>(-1);
if (!is_symlink_result && is_directory_result) {
count += remove_all(iter->path(), ec);
if (ec) {
@ -5568,9 +5587,11 @@ GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::operator+
GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::increment(std::error_code& ec) noexcept
{
auto status = (*this)->status(ec);
if (ec) return *this;
if (ec)
return *this;
auto symlink_status = (*this)->symlink_status(ec);
if (ec) return *this;
if (ec)
return *this;
if (recursion_pending() && is_directory(status) && (!is_symlink(symlink_status) || (options() & directory_options::follow_directory_symlink) != directory_options::none)) {
_impl->_dir_iter_stack.push(directory_iterator((*this)->path(), _impl->_options, ec));
}