From 9b0e3556edf9a77d8d782f56e064935e3e455242 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 9 Aug 2018 20:50:50 -0400 Subject: vfs_real: Add CreateFullPath to CreateFile Fixes bugs with calling CreateFile when the immediate directory does not exist. --- src/core/file_sys/vfs_real.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 1b5919737..fa682153c 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -83,7 +83,10 @@ 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) && !FileUtil::CreateEmptyFile(path)) + if (!FileUtil::Exists(path) && + !FileUtil::CreateFullPath( + FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash)) && + !FileUtil::CreateEmptyFile(path)) return nullptr; return OpenFile(path, perms); } @@ -306,14 +309,14 @@ RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& std::shared_ptr RealVfsDirectory::GetFileRelative(std::string_view path) const { const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path)); - if (!FileUtil::Exists(full_path)) + if (!FileUtil::Exists(full_path) || FileUtil::IsDirectory(full_path)) return nullptr; return base.OpenFile(full_path, perms); } std::shared_ptr RealVfsDirectory::GetDirectoryRelative(std::string_view path) const { const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path)); - if (!FileUtil::Exists(full_path)) + if (!FileUtil::Exists(full_path) || !FileUtil::IsDirectory(full_path)) return nullptr; return base.OpenDirectory(full_path, perms); } -- cgit v1.2.3 From 893447b6b0f5068f3cc2111b5f21c3cff68002e2 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 11 Aug 2018 15:39:09 -0400 Subject: registration: Update documentation and style --- src/core/file_sys/vfs_real.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 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 fa682153c..33ab35fcd 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -83,10 +83,12 @@ 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) && - !FileUtil::CreateFullPath( - FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash)) && - !FileUtil::CreateEmptyFile(path)) + if (!FileUtil::Exists(path)) + return nullptr; + if (!FileUtil::CreateFullPath( + FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash))) + return nullptr; + if (!FileUtil::CreateEmptyFile(path)) return nullptr; return OpenFile(path, perms); } @@ -143,7 +145,12 @@ 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) && !FileUtil::CreateDir(path)) + if (!FileUtil::Exists(path)) + return nullptr; + if (!FileUtil::CreateFullPath( + FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash))) + return nullptr; + if (!FileUtil::CreateDir(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 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 From 35e4a47be0c4ef25f860d51851d2c02c02dff53d Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 12 Aug 2018 15:55:44 -0400 Subject: registration: Various style and documentation improvements Fix logic in RealVfsFilesystem Create methods Remove magic numbers Fix regex errors --- src/core/file_sys/vfs_real.cpp | 16 ++++++++++------ 1 file changed, 10 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 02cdb039a..0afe515f0 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -84,9 +84,11 @@ 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); const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash); - if (!FileUtil::Exists(path) && !FileUtil::CreateFullPath(path_fwd) && - !FileUtil::CreateEmptyFile(path)) - return nullptr; + if (!FileUtil::Exists(path)) { + FileUtil::CreateFullPath(path_fwd); + if (!FileUtil::CreateEmptyFile(path)) + return nullptr; + } return OpenFile(path, perms); } @@ -143,9 +145,11 @@ 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); const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash); - if (!FileUtil::Exists(path) && !FileUtil::CreateFullPath(path_fwd) && - !FileUtil::CreateEmptyFile(path)) - return nullptr; + if (!FileUtil::Exists(path)) { + FileUtil::CreateFullPath(path_fwd); + if (!FileUtil::CreateDir(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