filesystem: use std for PathExists

Remove custom platform implementation of `PathExists` and replace uses
with `std::filesystem::exists`.
This commit is contained in:
Sandy Carter
2020-04-09 10:09:18 -04:00
committed by Rick Gibbed
parent a9fa38c88b
commit c8e64da4eb
12 changed files with 23 additions and 36 deletions

View File

@@ -17,7 +17,7 @@ namespace filesystem {
bool CreateParentFolder(const std::filesystem::path& path) {
if (path.has_parent_path()) {
auto parent_path = path.parent_path();
if (!PathExists(parent_path)) {
if (!std::filesystem::exists(parent_path)) {
return CreateFolder(parent_path);
}
}

View File

@@ -36,9 +36,6 @@ std::filesystem::path GetExecutableFolder();
// Get user folder.
std::filesystem::path GetUserFolder();
// Returns true of the specified path exists as either a directory or file.
bool PathExists(const std::filesystem::path& path);
// Creates the parent folder of the specified path if needed.
// This can be used to ensure the destination path for a new file exists before
// attempting to create it.

View File

@@ -77,11 +77,6 @@ std::filesystem::path GetUserFolder() {
return std::filesystem::path(home) / ".local" / "share";
}
bool PathExists(const std::filesystem::path& path) {
struct stat st;
return stat(path.c_str(), &st) == 0;
}
FILE* OpenFile(const std::filesystem::path& path, const std::string_view mode) {
return fopen(path.c_str(), std::string(mode).c_str());
}

View File

@@ -61,18 +61,13 @@ std::filesystem::path GetUserFolder() {
return result;
}
bool PathExists(const std::filesystem::path& path) {
DWORD attrib = GetFileAttributes(path.c_str());
return attrib != INVALID_FILE_ATTRIBUTES;
}
bool CreateFolder(const std::filesystem::path& path) {
std::filesystem::path create_path;
for (auto it = path.begin(); it != path.end(); ++it) {
create_path /= *it;
CreateDirectoryW(create_path.c_str(), nullptr);
}
return PathExists(path);
return std::filesystem::exists(path);
}
bool DeleteFolder(const std::filesystem::path& path) {