From 8f06a0f898fcade16f6ba9376cf4b72ff608f2ad Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 11 Aug 2018 22:47:25 -0400 Subject: vfs_real: Add CreateFullPath to Create* operations --- src/core/file_sys/vfs_real.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/core/file_sys/vfs_real.cpp') diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 33ab35fcd..02cdb039a 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -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(new RealVfsDirectory(*this, path, perms)); -- cgit v1.2.3