From 81b1b71993473b31321c8ff2d0dd0b267848a968 Mon Sep 17 00:00:00 2001 From: Morph Date: Sat, 19 Jun 2021 03:43:16 -0400 Subject: common: fs: Remove [[nodiscard]] attribute on Remove* functions There are a lot of scenarios where we don't particularly care whether or not the removal operation and just simply attempt a removal. As such, removing the [[nodiscard]] attribute is best for these functions. --- src/common/fs/fs.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/common/fs/fs.h') diff --git a/src/common/fs/fs.h b/src/common/fs/fs.h index f6f256349..cf7dfffcc 100644 --- a/src/common/fs/fs.h +++ b/src/common/fs/fs.h @@ -55,11 +55,11 @@ template * * @returns True if file removal succeeds or file does not exist, false otherwise. */ -[[nodiscard]] bool RemoveFile(const std::filesystem::path& path); +bool RemoveFile(const std::filesystem::path& path); #ifdef _WIN32 template -[[nodiscard]] bool RemoveFile(const Path& path) { +bool RemoveFile(const Path& path) { if constexpr (IsChar) { return RemoveFile(ToU8String(path)); } else { @@ -251,11 +251,11 @@ template * * @returns True if directory removal succeeds or directory does not exist, false otherwise. */ -[[nodiscard]] bool RemoveDir(const std::filesystem::path& path); +bool RemoveDir(const std::filesystem::path& path); #ifdef _WIN32 template -[[nodiscard]] bool RemoveDir(const Path& path) { +bool RemoveDir(const Path& path) { if constexpr (IsChar) { return RemoveDir(ToU8String(path)); } else { @@ -276,11 +276,11 @@ template * * @returns True if the directory and all of its contents are removed successfully, false otherwise. */ -[[nodiscard]] bool RemoveDirRecursively(const std::filesystem::path& path); +bool RemoveDirRecursively(const std::filesystem::path& path); #ifdef _WIN32 template -[[nodiscard]] bool RemoveDirRecursively(const Path& path) { +bool RemoveDirRecursively(const Path& path) { if constexpr (IsChar) { return RemoveDirRecursively(ToU8String(path)); } else { @@ -301,11 +301,11 @@ template * * @returns True if all of the directory's contents are removed successfully, false otherwise. */ -[[nodiscard]] bool RemoveDirContentsRecursively(const std::filesystem::path& path); +bool RemoveDirContentsRecursively(const std::filesystem::path& path); #ifdef _WIN32 template -[[nodiscard]] bool RemoveDirContentsRecursively(const Path& path) { +bool RemoveDirContentsRecursively(const Path& path) { if constexpr (IsChar) { return RemoveDirContentsRecursively(ToU8String(path)); } else { -- cgit v1.2.3 From 76b2313b25e2fd33a508f63137d5113e1ca85150 Mon Sep 17 00:00:00 2001 From: Morph Date: Sat, 19 Jun 2021 03:49:11 -0400 Subject: common: fs: Amend IsFile check in FileOpen / (Write/Append)StringToFile This check was preventing files with the Write or Append file access modes from being created, as per the documented behavior in FileAccessMode. This amends the check to test for the existence of a filesystem object prior to checking whether it is a regular file. Thanks to liushuyu for pointing out that removing the check altogether would not guard against attempting to open non-regular files such as directories, symlinks, FIFO (pipes), sockets, block devices, or character devices. The documentation has also been updated for these functions to clarify that a file refers to a regular file. --- src/common/fs/fs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common/fs/fs.h') diff --git a/src/common/fs/fs.h b/src/common/fs/fs.h index cf7dfffcc..a6c993962 100644 --- a/src/common/fs/fs.h +++ b/src/common/fs/fs.h @@ -110,8 +110,8 @@ template * * Failures occur when: * - Input path is not valid - * - Filesystem object at path is not a file - * - The file is not opened + * - Filesystem object at path exists and is not a regular file + * - The file is not open * * @param path Filesystem path * @param mode File access mode -- cgit v1.2.3 From 2fa207058ba6cb1c4d519942e5543bd942f03f6c Mon Sep 17 00:00:00 2001 From: Morph Date: Tue, 22 Jun 2021 15:06:17 -0400 Subject: common: fs: Add a description of a regular file in IsFile This provides a more concrete example of what a regular file is and isn't. --- src/common/fs/fs.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/common/fs/fs.h') diff --git a/src/common/fs/fs.h b/src/common/fs/fs.h index a6c993962..183126de3 100644 --- a/src/common/fs/fs.h +++ b/src/common/fs/fs.h @@ -48,7 +48,7 @@ template * * Failures occur when: * - Input path is not valid - * - Filesystem object at path is not a file + * - Filesystem object at path is not a regular file * - Filesystem at path is read only * * @param path Filesystem path @@ -74,7 +74,7 @@ bool RemoveFile(const Path& path) { * Failures occur when: * - One or both input path(s) is not valid * - Filesystem object at old_path does not exist - * - Filesystem object at old_path is not a file + * - Filesystem object at old_path is not a regular file * - Filesystem object at new_path exists * - Filesystem at either path is read only * @@ -435,11 +435,13 @@ template #endif /** - * Returns whether a filesystem object at path is a file. + * Returns whether a filesystem object at path is a regular file. + * A regular file is a file that stores text or binary data. + * It is not a directory, symlink, FIFO, socket, block device, or character device. * * @param path Filesystem path * - * @returns True if a filesystem object at path is a file, false otherwise. + * @returns True if a filesystem object at path is a regular file, false otherwise. */ [[nodiscard]] bool IsFile(const std::filesystem::path& path); -- cgit v1.2.3