Skip to content

Commit

Permalink
Replace uses of deprecated u8path
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Jun 20, 2024
1 parent 09e7cfe commit 35e9336
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Source/dvlnet/zerotier_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@ std::string ToZTCompliantPath(std::string_view configPath)
}

std::string symlinkPath = StrCat(alternateConfigPath, "\\", alternateFolderName);
bool symlinkExists = std::filesystem::exists(std::filesystem::u8path(symlinkPath), err);
bool symlinkExists = std::filesystem::exists(
std::u8string_view(reinterpret_cast<const char8_t *>(symlinkPath.data()), symlinkPath.size()), err);
if (err) {
LogVerbose("Failed to determine if symlink for ZT-compliant config path exists");
return std::string(configPath);
}

if (!symlinkExists) {
std::filesystem::create_directory_symlink(
std::filesystem::u8path(configPath),
std::filesystem::u8path(symlinkPath),
std::u8string_view(reinterpret_cast<const char8_t *>(configPath.data()), configPath.size()),
std::u8string_view(reinterpret_cast<const char8_t *>(symlinkPath.data()), symlinkPath.size()),
err);

if (err) {
Expand Down
12 changes: 6 additions & 6 deletions Source/utils/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool FileExists(const char *path)
return ::access(path, F_OK) == 0;
#elif defined(DVL_HAS_FILESYSTEM)
std::error_code ec;
return std::filesystem::exists(std::filesystem::u8path(path), ec);
return std::filesystem::exists(reinterpret_cast<const char8_t *>(path), ec);
#else
SDL_RWops *file = SDL_RWFromFile(path, "r+b");
if (file == nullptr)
Expand Down Expand Up @@ -154,7 +154,7 @@ bool DirectoryExists(const char *path)
return attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
#elif defined(DVL_HAS_FILESYSTEM)
std::error_code error;
return std::filesystem::is_directory(std::filesystem::u8path(path), error);
return std::filesystem::is_directory(reinterpret_cast<const char8_t *>(path), error);
#elif (_POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__)) && !defined(__ANDROID__)
struct ::stat statResult;
return ::stat(path, &statResult) == 0 && S_ISDIR(statResult.st_mode);
Expand Down Expand Up @@ -233,7 +233,7 @@ bool CreateDir(const char *path)
{
#ifdef DVL_HAS_FILESYSTEM
std::error_code error;
std::filesystem::create_directory(std::filesystem::u8path(path), error);
std::filesystem::create_directory(reinterpret_cast<const char8_t *>(path), error);
if (error) {
LogError("failed to create directory {}: {}", path, error.message());
return false;
Expand Down Expand Up @@ -274,7 +274,7 @@ void RecursivelyCreateDir(const char *path)
{
#ifdef DVL_HAS_FILESYSTEM
std::error_code error;
std::filesystem::create_directories(std::filesystem::u8path(path), error);
std::filesystem::create_directories(reinterpret_cast<const char8_t *>(path), error);
if (error) {
LogError("failed to create directory {}: {}", path, error.message());
}
Expand Down Expand Up @@ -373,7 +373,7 @@ void RenameFile(const char *from, const char *to)
#endif // _WIN32
#elif defined(DVL_HAS_FILESYSTEM)
std::error_code ec;
std::filesystem::rename(std::filesystem::u8path(from), std::filesystem::u8path(to), ec);
std::filesystem::rename(reinterpret_cast<const char8_t *>(from), reinterpret_cast<const char8_t *>(to), ec);
#else
::rename(from, to);
#endif
Expand Down Expand Up @@ -401,7 +401,7 @@ void CopyFileOverwrite(const char *from, const char *to)
::copyfile(from, to, nullptr, COPYFILE_ALL);
#elif defined(DVL_HAS_FILESYSTEM)
std::error_code error;
std::filesystem::copy_file(std::filesystem::u8path(from), std::filesystem::u8path(to), std::filesystem::copy_options::overwrite_existing, error);
std::filesystem::copy_file(reinterpret_cast<const char8_t *>(from), reinterpret_cast<const char8_t *>(to), std::filesystem::copy_options::overwrite_existing, error);
if (error) {
LogError("Failed to copy {} to {}: {}", from, to, error.message());
}
Expand Down

0 comments on commit 35e9336

Please sign in to comment.