From b06d6e36468c10864fefc33a4627e4ded36faae3 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 9 Dec 2020 05:05:32 -0500 Subject: vfs_real: Fix CreateFile for files without a file extension --- src/core/file_sys/vfs_real.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 488687ba9..3b70f7755 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -94,9 +94,13 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); - const auto path_fwd = FS::SanitizePath(path, FS::DirectorySeparator::ForwardSlash); + const auto parent_path = FS::GetParentPath(path); + if (!FS::Exists(path)) { - FS::CreateFullPath(path_fwd); + if (!FS::CreateDirs(parent_path)) { + return nullptr; + } + if (!FS::CreateEmptyFile(path)) { return nullptr; } -- cgit v1.2.3 From b1657b8c6b4ef07dd6eea92f4559a32ca3e0894a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 10 Dec 2020 01:31:58 -0500 Subject: vfs: Use existing type aliases consistently Makes use of the VirtualDir and VirtualFile aliases across the board instead of having a few isolated places that don't use it. --- src/core/file_sys/vfs_real.cpp | 24 ++++++++++++------------ 1 file changed, 12 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 3b70f7755..26ffd8a9d 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -267,7 +267,7 @@ bool RealVfsFile::Resize(std::size_t new_size) { return backing->Resize(new_size); } -std::shared_ptr RealVfsFile::GetContainingDirectory() const { +VirtualDir RealVfsFile::GetContainingDirectory() const { return base.OpenDirectory(parent_path, perms); } @@ -356,7 +356,7 @@ RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& RealVfsDirectory::~RealVfsDirectory() = default; -std::shared_ptr RealVfsDirectory::GetFileRelative(std::string_view path) const { +VirtualFile RealVfsDirectory::GetFileRelative(std::string_view path) const { const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); if (!FS::Exists(full_path) || FS::IsDirectory(full_path)) { return nullptr; @@ -364,7 +364,7 @@ std::shared_ptr RealVfsDirectory::GetFileRelative(std::string_view path return base.OpenFile(full_path, perms); } -std::shared_ptr RealVfsDirectory::GetDirectoryRelative(std::string_view path) const { +VirtualDir RealVfsDirectory::GetDirectoryRelative(std::string_view path) const { const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); if (!FS::Exists(full_path) || !FS::IsDirectory(full_path)) { return nullptr; @@ -372,20 +372,20 @@ std::shared_ptr RealVfsDirectory::GetDirectoryRelative(std::string return base.OpenDirectory(full_path, perms); } -std::shared_ptr RealVfsDirectory::GetFile(std::string_view name) const { +VirtualFile RealVfsDirectory::GetFile(std::string_view name) const { return GetFileRelative(name); } -std::shared_ptr RealVfsDirectory::GetSubdirectory(std::string_view name) const { +VirtualDir RealVfsDirectory::GetSubdirectory(std::string_view name) const { return GetDirectoryRelative(name); } -std::shared_ptr RealVfsDirectory::CreateFileRelative(std::string_view path) { +VirtualFile RealVfsDirectory::CreateFileRelative(std::string_view path) { const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); return base.CreateFile(full_path, perms); } -std::shared_ptr RealVfsDirectory::CreateDirectoryRelative(std::string_view path) { +VirtualDir RealVfsDirectory::CreateDirectoryRelative(std::string_view path) { const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); return base.CreateDirectory(full_path, perms); } @@ -395,11 +395,11 @@ bool RealVfsDirectory::DeleteSubdirectoryRecursive(std::string_view name) { return base.DeleteDirectory(full_path); } -std::vector> RealVfsDirectory::GetFiles() const { +std::vector RealVfsDirectory::GetFiles() const { return IterateEntries(); } -std::vector> RealVfsDirectory::GetSubdirectories() const { +std::vector RealVfsDirectory::GetSubdirectories() const { return IterateEntries(); } @@ -415,7 +415,7 @@ std::string RealVfsDirectory::GetName() const { return path_components.back(); } -std::shared_ptr RealVfsDirectory::GetParentDirectory() const { +VirtualDir RealVfsDirectory::GetParentDirectory() const { if (path_components.size() <= 1) { return nullptr; } @@ -423,12 +423,12 @@ std::shared_ptr RealVfsDirectory::GetParentDirectory() const { return base.OpenDirectory(parent_path, perms); } -std::shared_ptr RealVfsDirectory::CreateSubdirectory(std::string_view name) { +VirtualDir RealVfsDirectory::CreateSubdirectory(std::string_view name) { const std::string subdir_path = (path + DIR_SEP).append(name); return base.CreateDirectory(subdir_path, perms); } -std::shared_ptr RealVfsDirectory::CreateFile(std::string_view name) { +VirtualFile RealVfsDirectory::CreateFile(std::string_view name) { const std::string file_path = (path + DIR_SEP).append(name); return base.CreateFile(file_path, perms); } -- cgit v1.2.3 From dfee6321cd313ae72019d9717de95e8b3f9a4728 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Fri, 11 Dec 2020 20:23:40 -0500 Subject: Revert "Merge pull request #5176 from Morph1984/fix-createfile" This reverts commit 6d6115475b4edccdf1bb4e96ecc3d3b1be319e76, reversing changes made to 5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a. --- src/core/file_sys/vfs_real.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 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 3b70f7755..488687ba9 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -94,13 +94,9 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); - const auto parent_path = FS::GetParentPath(path); - + const auto path_fwd = FS::SanitizePath(path, FS::DirectorySeparator::ForwardSlash); if (!FS::Exists(path)) { - if (!FS::CreateDirs(parent_path)) { - return nullptr; - } - + FS::CreateFullPath(path_fwd); if (!FS::CreateEmptyFile(path)) { return nullptr; } -- cgit v1.2.3