vfs_real: Add CreateFullPath to Create* operations

This commit is contained in:
Zach Hilman 2018-08-11 22:47:25 -04:00
parent dda8ef11c7
commit 8f06a0f898
2 changed files with 6 additions and 13 deletions

View file

@ -83,12 +83,9 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) {
VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) {
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
if (!FileUtil::Exists(path))
return nullptr;
if (!FileUtil::CreateFullPath(
FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash)))
return nullptr;
if (!FileUtil::CreateEmptyFile(path))
const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash);
if (!FileUtil::Exists(path) && !FileUtil::CreateFullPath(path_fwd) &&
!FileUtil::CreateEmptyFile(path))
return nullptr;
return OpenFile(path, perms);
}
@ -145,12 +142,9 @@ VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms)
VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) {
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
if (!FileUtil::Exists(path))
return nullptr;
if (!FileUtil::CreateFullPath(
FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash)))
return nullptr;
if (!FileUtil::CreateDir(path))
const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash);
if (!FileUtil::Exists(path) && !FileUtil::CreateFullPath(path_fwd) &&
!FileUtil::CreateEmptyFile(path))
return nullptr;
// Cannot use make_shared as RealVfsDirectory constructor is private
return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms));

View file

@ -5,7 +5,6 @@
#pragma once
#include <string_view>
#include <boost/container/flat_map.hpp>
#include "common/file_util.h"
#include "core/file_sys/mode.h"