From 3bf488ce520a81811bf6e949e2153aabf4b713ea Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 3 Aug 2018 11:46:30 -0400 Subject: vfs: Add VfsFilesystem interface and default implementation --- src/core/file_sys/vfs.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index fab9e2b45..9c7ef93b8 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -11,14 +11,74 @@ #include #include "boost/optional.hpp" #include "common/common_types.h" +#include "core/file_sys/mode.h" namespace FileSys { + +struct VfsFilesystem; struct VfsFile; struct VfsDirectory; -// Convenience typedefs to use VfsDirectory and VfsFile -using VirtualDir = std::shared_ptr; -using VirtualFile = std::shared_ptr; +// Convenience typedefs to use Vfs* interfaces +using VirtualFilesystem = std::shared_ptr; +using VirtualDir = std::shared_ptr; +using VirtualFile = std::shared_ptr; + +// An enumeration representing what can be at the end of a path in a VfsFilesystem +enum class VfsEntryType { + None, + File, + Directory, +}; + +// A class represnting an abstract filesystem. A default implementation given the root VirtualDir is +// provided for convenience, but if the Vfs implementation has any additional state or +// functionality, they will need to override. +struct VfsFilesystem : NonCopyable { + VfsFilesystem(VirtualDir root); + virtual ~VfsFilesystem(); + + // Gets the friendly name for the filesystem. + virtual std::string GetName() const; + + // Return whether or not the user has read permissions on this filesystem. + virtual bool IsReadable() const; + // Return whether or not the user has write permission on this filesystem. + virtual bool IsWritable() const; + + // Determine if the entry at path is non-existant, a file, or a directory. + virtual VfsEntryType GetEntryType(std::string_view path) const; + + // Opens the file with path relative to root. If it doesn't exist, returns nullptr. + virtual VirtualFile OpenFile(std::string_view path, Mode perms); + // Creates a new, empty file at path + virtual VirtualFile CreateFile(std::string_view path, Mode perms); + // Copies the file from old_path to new_path, returning the new file on success and nullptr on + // failure. + virtual VirtualFile CopyFile(std::string_view old_path, std::string_view new_path); + // Moves the file from old_path to new_path, returning the moved file on success and nullptr on + // failure. + virtual VirtualFile MoveFile(std::string_view old_path, std::string_view new_path); + // Deletes the file with path relative to root, returing true on success. + virtual bool DeleteFile(std::string_view path); + + // Opens the directory with path relative to root. If it doesn't exist, returns nullptr. + virtual VirtualDir OpenDirectory(std::string_view path, Mode perms); + // Creates a new, empty directory at path + virtual VirtualDir CreateDirectory(std::string_view path, Mode perms); + // Copies the directory from old_path to new_path, returning the new directory on success and + // nullptr on failure. + virtual VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path); + // Moves the directory from old_path to new_path, returning the moved directory on success and + // nullptr on failure. + virtual VirtualDir MoveDirectory(std::string_view old_path, std::string_view new_path); + // Deletes the directory with path relative to root, returing true on success. + virtual bool DeleteDirectory(std::string_view path); + +protected: + // Root directory in default implementation. + VirtualDir root; +}; // A class representing a file in an abstract filesystem. struct VfsFile : NonCopyable { -- cgit v1.2.3 From 94cf327e776eff934052847346d8415d584b369b Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 8 Aug 2018 14:34:06 -0400 Subject: vfs: Fix typo in VfsFilesystem docs --- src/core/file_sys/vfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index 9c7ef93b8..bf16e7286 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -31,7 +31,7 @@ enum class VfsEntryType { Directory, }; -// A class represnting an abstract filesystem. A default implementation given the root VirtualDir is +// A class representing an abstract filesystem. A default implementation given the root VirtualDir is // provided for convenience, but if the Vfs implementation has any additional state or // functionality, they will need to override. struct VfsFilesystem : NonCopyable { -- cgit v1.2.3 From 668458525ede125509ee27388221247b639f4676 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 8 Aug 2018 21:44:59 -0400 Subject: vfs: Fix documentation --- src/core/file_sys/vfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index bf16e7286..141a053ce 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -31,8 +31,8 @@ enum class VfsEntryType { Directory, }; -// A class representing an abstract filesystem. A default implementation given the root VirtualDir is -// provided for convenience, but if the Vfs implementation has any additional state or +// A class representing an abstract filesystem. A default implementation given the root VirtualDir +// is provided for convenience, but if the Vfs implementation has any additional state or // functionality, they will need to override. struct VfsFilesystem : NonCopyable { VfsFilesystem(VirtualDir root); -- cgit v1.2.3