aboutsummaryrefslogtreecommitdiff
path: root/src/common/fs/fs.cpp
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2021-06-19 03:49:11 -0400
committerMorph <39850852+Morph1984@users.noreply.github.com>2021-06-22 15:06:58 -0400
commitf158fd9dd168e1fcb3c48a0a33e2dde502ae3e1b (patch)
treeda79f542733f16ca27b834da5805a75503b1019a /src/common/fs/fs.cpp
parente12844c5a3ed8e41aaaedaa3575c463ded05d21d (diff)
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.
Diffstat (limited to 'src/common/fs/fs.cpp')
-rw-r--r--src/common/fs/fs.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/common/fs/fs.cpp b/src/common/fs/fs.cpp
index d3159e908c..9089cad67b 100644
--- a/src/common/fs/fs.cpp
+++ b/src/common/fs/fs.cpp
@@ -135,8 +135,9 @@ std::shared_ptr<IOFile> FileOpen(const fs::path& path, FileAccessMode mode, File
return nullptr;
}
- if (!IsFile(path)) {
- LOG_ERROR(Common_Filesystem, "Filesystem object at path={} is not a file",
+ if (Exists(path) && !IsFile(path)) {
+ LOG_ERROR(Common_Filesystem,
+ "Filesystem object at path={} exists and is not a regular file",
PathToUTF8String(path));
return nullptr;
}