MSVC bug workaround

This commit is contained in:
Eladash 2020-09-25 09:42:41 +03:00 committed by kd-11
parent 6164b3d2e2
commit 3b11f22062
4 changed files with 11 additions and 25 deletions

View File

@ -325,12 +325,6 @@ std::string fs::get_parent_dir(const std::string& path)
// Search upper bound (set to the last character, npos for empty string)
auto last = path.size() - 1;
#ifdef _WIN32
const auto& delim = "/\\";
#else
const auto& delim = "/";
#endif
while (true)
{
const auto pos = path.find_last_of(delim, last, sizeof(delim) - 1);
@ -355,13 +349,13 @@ bool fs::stat(const std::string& path, stat_t& info)
std::string_view epath = path;
// '/' and '\\' Not allowed by FindFirstFileExW at the end of path but we should allow it
if (auto not_del = epath.find_last_not_of("/\\"); not_del != umax && not_del != epath.size() - 1)
if (auto not_del = epath.find_last_not_of(delim); not_del != umax && not_del != epath.size() - 1)
{
epath.remove_suffix(epath.size() - 1 - not_del);
}
// Handle drives specially
if (epath.find_first_of("/\\") == umax && epath.ends_with(':'))
if (epath.find_first_of(delim) == umax && epath.ends_with(':'))
{
WIN32_FILE_ATTRIBUTE_DATA attrs;
@ -411,7 +405,7 @@ bool fs::stat(const std::string& path, stat_t& info)
~close_t() { FindClose(handle); }
};
for (close_t find_manage{handle}; attrs.cFileName != wpath_view.substr(wpath_view.find_last_of(L"/\\") + 1);)
for (close_t find_manage{handle}; attrs.cFileName != wpath_view.substr(wpath_view.find_last_of(wdelim) + 1);)
{
if (!FindNextFileW(handle, &attrs))
{
@ -1620,12 +1614,6 @@ std::string fs::escape_path(std::string_view path)
{
std::string real; real.resize(path.size());
#ifdef _WIN32
constexpr auto& delim = "/\\";
#else
constexpr auto& delim = "/";
#endif
auto get_char = [&](std::size_t& from, std::size_t& to, std::size_t count)
{
std::memcpy(&real[to], &path[from], count);

View File

@ -8,12 +8,15 @@
#include <vector>
#include <algorithm>
namespace fs
{
#ifdef _WIN32
static constexpr auto delim = "/\\";
static constexpr auto wdelim = L"/\\";
using native_handle = void*;
#else
static constexpr auto delim = "/";
static constexpr auto wdelim = L"/";
using native_handle = int;
#endif

View File

@ -8,6 +8,7 @@
#include <time.h>
#include "Utilities/StrUtil.h"
#include "Utilities/span.h"
#include "Utilities/File.h"
#include <memory>
#include <string>
@ -124,7 +125,7 @@ char* extract_file_name(const char* file_path, char real_file_name[MAX_PATH])
{
std::string_view v(file_path);
if (auto pos = v.find_last_of("/\\"); pos != umax)
if (auto pos = v.find_last_of(fs::delim); pos != umax)
{
v.remove_prefix(pos + 1);
}

View File

@ -712,14 +712,8 @@ std::string vfs::host::hash_path(const std::string& path, const std::string& dev
bool vfs::host::rename(const std::string& from, const std::string& to, const lv2_fs_mount_point* mp, bool overwrite)
{
#ifdef _WIN32
constexpr auto& delim = "/\\";
#else
constexpr auto& delim = "/";
#endif
// Lock mount point, close file descriptors, retry
const auto from0 = std::string_view(from).substr(0, from.find_last_not_of(delim) + 1);
const auto from0 = std::string_view(from).substr(0, from.find_last_not_of(fs::delim) + 1);
const auto escaped_from = fs::escape_path(from);
// Lock app_home as well because it could be in the same drive as current mount point (TODO)
@ -727,7 +721,7 @@ bool vfs::host::rename(const std::string& from, const std::string& to, const lv2
auto check_path = [&](std::string_view path)
{
return path.starts_with(from) && (path.size() == from.size() || path[from.size()] == delim[0] || path[from.size()] == delim[1]);
return path.starts_with(from) && (path.size() == from.size() || path[from.size()] == fs::delim[0] || path[from.size()] == fs::delim[1]);
};
idm::select<lv2_fs_object, lv2_file>([&](u32 id, lv2_file& file)