mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
refs #90, fixing stuff broken on POSIX side during backend rework.
This commit is contained in:
parent
c96b0059c3
commit
a7abc2ad4a
@ -130,12 +130,12 @@
|
|||||||
#else
|
#else
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
|
||||||
#ifdef GHC_OS_ANDROID
|
#ifdef GHC_OS_ANDROID
|
||||||
#include <android/api-level.h>
|
#include <android/api-level.h>
|
||||||
#if __ANDROID_API__ < 12
|
#if __ANDROID_API__ < 12
|
||||||
@ -281,7 +281,6 @@ template <typename char_type>
|
|||||||
constexpr char_type path_helper_base<char_type>::preferred_separator;
|
constexpr char_type path_helper_base<char_type>::preferred_separator;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef GHC_OS_WINDOWS
|
#ifdef GHC_OS_WINDOWS
|
||||||
class path;
|
class path;
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@ -289,7 +288,6 @@ bool has_executable_extension(const path& p);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// 30.10.8 class path
|
// 30.10.8 class path
|
||||||
class GHC_FS_API_CLASS path
|
class GHC_FS_API_CLASS path
|
||||||
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE)
|
#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);
|
friend path canonical(const path& p, std::error_code& ec);
|
||||||
string_type::size_type root_name_length() const noexcept;
|
string_type::size_type root_name_length() const noexcept;
|
||||||
void postprocess_path_with_format(format fmt);
|
void postprocess_path_with_format(format fmt);
|
||||||
|
void check_long_path();
|
||||||
impl_string_type _path;
|
impl_string_type _path;
|
||||||
#ifdef GHC_OS_WINDOWS
|
#ifdef GHC_OS_WINDOWS
|
||||||
void handle_prefixes();
|
void handle_prefixes();
|
||||||
void check_long_path();
|
|
||||||
friend bool detail::has_executable_extension(const path& p);
|
friend bool detail::has_executable_extension(const path& p);
|
||||||
#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH
|
#ifdef GHC_WIN_AUTO_PREFIX_LONG_PATH
|
||||||
string_type::size_type _prefixLength{0};
|
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()
|
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("\\\\?\\"))) {
|
if (is_absolute() && _path.length() >= MAX_PATH - 12 && !detail::startsWith(_path, impl_string_type("\\\\?\\"))) {
|
||||||
postprocess_path_with_format(native_format);
|
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)
|
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)) {
|
while (len1 > 0 && len2 > 0 && ::tolower((unsigned char)*str1) == ::tolower((unsigned char)*str2)) {
|
||||||
--len1; --len2;
|
--len1;
|
||||||
++str1; ++str2;
|
--len2;
|
||||||
|
++str1;
|
||||||
|
++str2;
|
||||||
}
|
}
|
||||||
if (len1 && len2) {
|
if (len1 && len2) {
|
||||||
return *str1 < *str2 ? -1 : 1;
|
return *str1 < *str2 ? -1 : 1;
|
||||||
@ -1903,7 +1903,8 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec)
|
|||||||
switch (reparseData->ReparseTag) {
|
switch (reparseData->ReparseTag) {
|
||||||
case IO_REPARSE_TAG_SYMLINK: {
|
case IO_REPARSE_TAG_SYMLINK: {
|
||||||
auto printName = std::wstring(&reparseData->SymbolicLinkReparseBuffer.PathBuffer[reparseData->SymbolicLinkReparseBuffer.PrintNameOffset / sizeof(WCHAR)], reparseData->SymbolicLinkReparseBuffer.PrintNameLength / sizeof(WCHAR));
|
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"\\??\\"))) {
|
if (detail::endsWith(substituteName, printName) && detail::startsWith(substituteName, std::wstring(L"\\??\\"))) {
|
||||||
result = printName;
|
result = printName;
|
||||||
}
|
}
|
||||||
@ -2167,13 +2168,17 @@ GHC_INLINE path::path() noexcept {}
|
|||||||
|
|
||||||
GHC_INLINE path::path(const path& p)
|
GHC_INLINE path::path(const path& p)
|
||||||
: _path(p._path)
|
: _path(p._path)
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
, _prefixLength(p._prefixLength)
|
, _prefixLength(p._prefixLength)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GHC_INLINE path::path(path&& p) noexcept
|
GHC_INLINE path::path(path&& p) noexcept
|
||||||
: _path(std::move(p._path))
|
: _path(std::move(p._path))
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
, _prefixLength(p._prefixLength)
|
, _prefixLength(p._prefixLength)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2221,14 +2226,18 @@ GHC_INLINE path::~path() {}
|
|||||||
GHC_INLINE path& path::operator=(const path& p)
|
GHC_INLINE path& path::operator=(const path& p)
|
||||||
{
|
{
|
||||||
_path = p._path;
|
_path = p._path;
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
_prefixLength = p._prefixLength;
|
_prefixLength = p._prefixLength;
|
||||||
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GHC_INLINE path& path::operator=(path&& p) noexcept
|
GHC_INLINE path& path::operator=(path&& p) noexcept
|
||||||
{
|
{
|
||||||
_path = std::move(p._path);
|
_path = std::move(p._path);
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
_prefixLength = p._prefixLength;
|
_prefixLength = p._prefixLength;
|
||||||
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2268,7 +2277,9 @@ template <>
|
|||||||
inline path& path::assign<path>(const path& source)
|
inline path& path::assign<path>(const path& source)
|
||||||
{
|
{
|
||||||
_path = source._path;
|
_path = source._path;
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
_prefixLength = source._prefixLength;
|
_prefixLength = source._prefixLength;
|
||||||
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2445,7 +2456,9 @@ inline path& path::concat(InputIterator first, InputIterator last)
|
|||||||
GHC_INLINE void path::clear() noexcept
|
GHC_INLINE void path::clear() noexcept
|
||||||
{
|
{
|
||||||
_path.clear();
|
_path.clear();
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
_prefixLength = 0;
|
_prefixLength = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GHC_INLINE path& path::make_preferred()
|
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
|
GHC_INLINE void path::swap(path& rhs) noexcept
|
||||||
{
|
{
|
||||||
_path.swap(rhs._path);
|
_path.swap(rhs._path);
|
||||||
|
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_AUTO_PREFIX_LONG_PATH)
|
||||||
std::swap(_prefixLength, rhs._prefixLength);
|
std::swap(_prefixLength, rhs._prefixLength);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -2579,7 +2594,7 @@ inline std::basic_string<EcharT, traits, Allocator> path::generic_string(const A
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
return _path:
|
return detail::fromUtf8<std::basic_string<EcharT, traits, Allocator>>(_path, a);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2590,7 +2605,7 @@ GHC_INLINE std::string path::generic_string() const
|
|||||||
#ifdef GHC_OS_WINDOWS
|
#ifdef GHC_OS_WINDOWS
|
||||||
return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
|
return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
|
||||||
#else
|
#else
|
||||||
return _path:
|
return _path;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2618,7 +2633,7 @@ GHC_INLINE std::string path::generic_u8string() const
|
|||||||
#ifdef GHC_OS_WINDOWS
|
#ifdef GHC_OS_WINDOWS
|
||||||
return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
|
return generic_string<std::string::value_type, std::string::traits_type, std::string::allocator_type>();
|
||||||
#else
|
#else
|
||||||
return _path:
|
return _path;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2717,17 +2732,19 @@ GHC_INLINE int path::compare(const value_type* s) const
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// 30.10.8.4.9, decomposition
|
// 30.10.8.4.9, decomposition
|
||||||
|
#ifdef GHC_OS_WINDOWS
|
||||||
GHC_INLINE void path::handle_prefixes()
|
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;
|
_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 (_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("\\??\\"))) {
|
if (detail::startsWith(_path, impl_string_type("\\\\?\\")) || detail::startsWith(_path, impl_string_type("\\??\\"))) {
|
||||||
_prefixLength = 4;
|
_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
|
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 (i != _last) {
|
||||||
if (fromStart && i == _first && _prefix > _first) {
|
if (fromStart && i == _first && _prefix > _first) {
|
||||||
i = _prefix;
|
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
|
// we can only sit on a slash if it is a network name or a root
|
||||||
if (i != _last && *i == internal_separator) {
|
if (i != _last && *i == internal_separator) {
|
||||||
if (fromStart && !(i + 1 != _last && *(i + 1) == 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;
|
return lhs.compare(rhs) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GHC_INLINE path operator/(const path& lhs, const path& rhs)
|
GHC_INLINE path operator/(const path& lhs, const path& rhs)
|
||||||
{
|
{
|
||||||
path result(lhs);
|
path result(lhs);
|
||||||
@ -3431,7 +3448,6 @@ GHC_INLINE path canonical(const path& p, std::error_code& ec)
|
|||||||
result /= target;
|
result /= target;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result /= pe;
|
result /= pe;
|
||||||
@ -3698,7 +3714,8 @@ GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept
|
|||||||
std::error_code tmp_ec;
|
std::error_code tmp_ec;
|
||||||
if (is_directory(current, tmp_ec)) {
|
if (is_directory(current, tmp_ec)) {
|
||||||
ec.clear();
|
ec.clear();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4515,9 +4532,11 @@ GHC_INLINE uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bool is_symlink_result = iter->is_symlink(ec);
|
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);
|
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) {
|
if (!is_symlink_result && is_directory_result) {
|
||||||
count += remove_all(iter->path(), ec);
|
count += remove_all(iter->path(), ec);
|
||||||
if (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
|
GHC_INLINE recursive_directory_iterator& recursive_directory_iterator::increment(std::error_code& ec) noexcept
|
||||||
{
|
{
|
||||||
auto status = (*this)->status(ec);
|
auto status = (*this)->status(ec);
|
||||||
if (ec) return *this;
|
if (ec)
|
||||||
|
return *this;
|
||||||
auto symlink_status = (*this)->symlink_status(ec);
|
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)) {
|
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));
|
_impl->_dir_iter_stack.push(directory_iterator((*this)->path(), _impl->_options, ec));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user