From be1954e04cb5a0c3a526f78ed5490a5e65310280 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Oct 2020 14:49:45 -0400 Subject: core: Fix clang build Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795 --- src/common/file_util.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 8b587320f..508b7a10a 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -189,7 +189,8 @@ template return {}; } last = std::min(last, vector.size()); - return std::vector(vector.begin() + first, vector.begin() + first + last); + return std::vector(vector.begin() + static_cast(first), + vector.begin() + static_cast(first + last)); } enum class DirectorySeparator { -- cgit v1.2.3 From 3d592972dc3fd61cc88771b889eff237e4e03e0f Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 20 Oct 2020 19:07:39 -0700 Subject: Revert "core: Fix clang build" --- src/common/file_util.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 508b7a10a..8b587320f 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -189,8 +189,7 @@ template return {}; } last = std::min(last, vector.size()); - return std::vector(vector.begin() + static_cast(first), - vector.begin() + static_cast(first + last)); + return std::vector(vector.begin() + first, vector.begin() + first + last); } enum class DirectorySeparator { -- cgit v1.2.3 From 26547d3e3be403047445fd39e671d7ef3b88dabb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 29 Oct 2020 23:30:42 -0400 Subject: General: Make ignoring a discarded return value an error Allows our CI to catch more potential bugs. This also removes the [[nodiscard]] attribute of IOFile's Open member function. There are cases where a file may want to be opened, but have the status of it checked at a later time. --- src/common/file_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 8b587320f..840cde2a6 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -232,7 +232,7 @@ public: void Swap(IOFile& other) noexcept; - [[nodiscard]] bool Open(const std::string& filename, const char openmode[], int flags = 0); + bool Open(const std::string& filename, const char openmode[], int flags = 0); bool Close(); template -- cgit v1.2.3 From 0e54aa17e64a5c5b62d60a70414742be29eccff9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 8 Dec 2020 18:36:49 -0500 Subject: file_util: Migrate Exists() and IsDirectory() over to std::filesystem Greatly simplifies our file-handling code for these functions. --- src/common/file_util.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 840cde2a6..be0906434 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -47,11 +48,11 @@ struct FSTEntry { std::vector children; }; -// Returns true if file filename exists -[[nodiscard]] bool Exists(const std::string& filename); +// Returns true if the exists +[[nodiscard]] bool Exists(const std::filesystem::path& path); -// Returns true if filename is a directory -[[nodiscard]] bool IsDirectory(const std::string& filename); +// Returns true if path is a directory +[[nodiscard]] bool IsDirectory(const std::filesystem::path& path); // Returns the size of filename (64bit) [[nodiscard]] u64 GetSize(const std::string& filename); -- cgit v1.2.3 From 20aad9e01af958b6c8bf7d18faebd498541651f5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 8 Dec 2020 18:51:04 -0500 Subject: file_util: Migrate remaining file handling functions over to std::filesystem Converts creation and deletion functions over to std::filesystem, simplifying our file-handling code. Notably with this, CopyDir will now function on Windows. --- src/common/file_util.h | 62 ++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index be0906434..c2ee7ca27 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -39,48 +39,34 @@ enum class UserPath { UserDir, }; -// FileSystem tree node/ -struct FSTEntry { - bool isDirectory; - u64 size; // file length or number of entries from children - std::string physicalName; // name on disk - std::string virtualName; // name in FST names table - std::vector children; -}; - -// Returns true if the exists +// Returns true if the path exists [[nodiscard]] bool Exists(const std::filesystem::path& path); // Returns true if path is a directory [[nodiscard]] bool IsDirectory(const std::filesystem::path& path); // Returns the size of filename (64bit) -[[nodiscard]] u64 GetSize(const std::string& filename); - -// Overloaded GetSize, accepts file descriptor -[[nodiscard]] u64 GetSize(int fd); +[[nodiscard]] u64 GetSize(const std::filesystem::path& path); // Overloaded GetSize, accepts FILE* [[nodiscard]] u64 GetSize(FILE* f); // Returns true if successful, or path already exists. -bool CreateDir(const std::string& filename); - -// Creates the full path of fullPath returns true on success -bool CreateFullPath(const std::string& fullPath); +bool CreateDir(const std::filesystem::path& path); -// Deletes a given filename, return true on success -// Doesn't supports deleting a directory -bool Delete(const std::string& filename); +// Creates the full path of path. Returns true on success +bool CreateFullPath(const std::filesystem::path& path); -// Deletes a directory filename, returns true on success -bool DeleteDir(const std::string& filename); +// Deletes a given file at the path. +// This will also delete empty directories. +// Return true on success +bool Delete(const std::filesystem::path& path); -// renames file srcFilename to destFilename, returns true on success -bool Rename(const std::string& srcFilename, const std::string& destFilename); +// Renames file src to dst, returns true on success +bool Rename(const std::filesystem::path& src, const std::filesystem::path& dst); -// copies file srcFilename to destFilename, returns true on success -bool Copy(const std::string& srcFilename, const std::string& destFilename); +// copies file src to dst, returns true on success +bool Copy(const std::filesystem::path& src, const std::filesystem::path& dst); // creates an empty file filename, returns true on success bool CreateEmptyFile(const std::string& filename); @@ -107,27 +93,17 @@ using DirectoryEntryCallable = std::function GetCurrentDir(); +[[nodiscard]] std::optional GetCurrentDir(); // Create directory and copy contents (does not overwrite existing files) -void CopyDir(const std::string& source_path, const std::string& dest_path); +void CopyDir(const std::filesystem::path& src, const std::filesystem::path& dst); -// Set the current directory to given directory -bool SetCurrentDir(const std::string& directory); +// Set the current directory to given path +bool SetCurrentDir(const std::filesystem::path& path); // Returns a pointer to a string with a yuzu data dir in the user's home // directory. To be used in "multi-user" mode (that is, installed). -- cgit v1.2.3 From 532983437616e15539b448594a360c138995e282 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 9 Dec 2020 05:22:16 -0300 Subject: common/file_util: Fix and deprecate CreateFullPath, add CreateDirs Fix CreateFullPath to have its intended previous behavior (whatever that was), and deprecate it in favor of the new CreateDirs function. Unlike CreateDir, CreateDirs is marked as [[nodiscard]] to avoid new code ignoring its result value. --- src/common/file_util.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index c2ee7ca27..cf006cc9d 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -54,8 +54,14 @@ enum class UserPath { // Returns true if successful, or path already exists. bool CreateDir(const std::filesystem::path& path); -// Creates the full path of path. Returns true on success -bool CreateFullPath(const std::filesystem::path& path); +// Create all directories in path +// Returns true if successful, or path already exists. +[[nodiscard("Directory creation can fail and must be tested")]] bool CreateDirs( + const std::filesystem::path& path); + +// Creates directories in path. Returns true on success. +[[deprecated("This function is deprecated, use CreateDirs")]] bool CreateFullPath( + const std::filesystem::path& path); // Deletes a given file at the path. // This will also delete empty directories. -- cgit v1.2.3 From 8941cdb7d2355ba0f3084b306165923520f9db65 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Fri, 11 Dec 2020 20:22:01 -0500 Subject: Revert "Merge pull request #5174 from ReinUsesLisp/fs-fix" This reverts commit 5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a, reversing changes made to e94dd7e2c4fc3f7ca2c15c01bdc301be2b8a4c1b. --- src/common/file_util.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index cf006cc9d..c2ee7ca27 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -54,14 +54,8 @@ enum class UserPath { // Returns true if successful, or path already exists. bool CreateDir(const std::filesystem::path& path); -// Create all directories in path -// Returns true if successful, or path already exists. -[[nodiscard("Directory creation can fail and must be tested")]] bool CreateDirs( - const std::filesystem::path& path); - -// Creates directories in path. Returns true on success. -[[deprecated("This function is deprecated, use CreateDirs")]] bool CreateFullPath( - const std::filesystem::path& path); +// Creates the full path of path. Returns true on success +bool CreateFullPath(const std::filesystem::path& path); // Deletes a given file at the path. // This will also delete empty directories. -- cgit v1.2.3 From 4de079b256ce320c7e261a2c35b703e477e46fa5 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Fri, 11 Dec 2020 20:22:18 -0500 Subject: Revert "Merge pull request #5173 from lioncash/common-fs" This reverts commit ce5fcb6bb2c358b0251a2ce87945bda52789a76d, reversing changes made to 6f41763061082d5fa2ab039c554427152243cb46. --- src/common/file_util.h | 69 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 23 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index c2ee7ca27..840cde2a6 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -39,34 +38,48 @@ enum class UserPath { UserDir, }; -// Returns true if the path exists -[[nodiscard]] bool Exists(const std::filesystem::path& path); +// FileSystem tree node/ +struct FSTEntry { + bool isDirectory; + u64 size; // file length or number of entries from children + std::string physicalName; // name on disk + std::string virtualName; // name in FST names table + std::vector children; +}; + +// Returns true if file filename exists +[[nodiscard]] bool Exists(const std::string& filename); -// Returns true if path is a directory -[[nodiscard]] bool IsDirectory(const std::filesystem::path& path); +// Returns true if filename is a directory +[[nodiscard]] bool IsDirectory(const std::string& filename); // Returns the size of filename (64bit) -[[nodiscard]] u64 GetSize(const std::filesystem::path& path); +[[nodiscard]] u64 GetSize(const std::string& filename); + +// Overloaded GetSize, accepts file descriptor +[[nodiscard]] u64 GetSize(int fd); // Overloaded GetSize, accepts FILE* [[nodiscard]] u64 GetSize(FILE* f); // Returns true if successful, or path already exists. -bool CreateDir(const std::filesystem::path& path); +bool CreateDir(const std::string& filename); + +// Creates the full path of fullPath returns true on success +bool CreateFullPath(const std::string& fullPath); -// Creates the full path of path. Returns true on success -bool CreateFullPath(const std::filesystem::path& path); +// Deletes a given filename, return true on success +// Doesn't supports deleting a directory +bool Delete(const std::string& filename); -// Deletes a given file at the path. -// This will also delete empty directories. -// Return true on success -bool Delete(const std::filesystem::path& path); +// Deletes a directory filename, returns true on success +bool DeleteDir(const std::string& filename); -// Renames file src to dst, returns true on success -bool Rename(const std::filesystem::path& src, const std::filesystem::path& dst); +// renames file srcFilename to destFilename, returns true on success +bool Rename(const std::string& srcFilename, const std::string& destFilename); -// copies file src to dst, returns true on success -bool Copy(const std::filesystem::path& src, const std::filesystem::path& dst); +// copies file srcFilename to destFilename, returns true on success +bool Copy(const std::string& srcFilename, const std::string& destFilename); // creates an empty file filename, returns true on success bool CreateEmptyFile(const std::string& filename); @@ -93,17 +106,27 @@ using DirectoryEntryCallable = std::function GetCurrentDir(); +[[nodiscard]] std::optional GetCurrentDir(); // Create directory and copy contents (does not overwrite existing files) -void CopyDir(const std::filesystem::path& src, const std::filesystem::path& dst); +void CopyDir(const std::string& source_path, const std::string& dest_path); -// Set the current directory to given path -bool SetCurrentDir(const std::filesystem::path& path); +// Set the current directory to given directory +bool SetCurrentDir(const std::string& directory); // Returns a pointer to a string with a yuzu data dir in the user's home // directory. To be used in "multi-user" mode (that is, installed). -- cgit v1.2.3