aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-10-16 09:49:55 +0200
committerGitHub Enterprise <[email protected]>2024-10-16 09:49:55 +0200
commitb254f75968e1a5692fa872fcfda5eaa1a0ed561d (patch)
tree968e5fc30e37295a4c5767d5c290016116e196ab /src/zencore/filesystem.cpp
parentupload linux mac exe to sentry (#196) (diff)
downloadzen-b254f75968e1a5692fa872fcfda5eaa1a0ed561d.tar.xz
zen-b254f75968e1a5692fa872fcfda5eaa1a0ed561d.zip
safer path from handle (#195)
* remove PathFromHandle that throws to give better context on failures
Diffstat (limited to 'src/zencore/filesystem.cpp')
-rw-r--r--src/zencore/filesystem.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp
index 7ca076daa..ac2aabbf0 100644
--- a/src/zencore/filesystem.cpp
+++ b/src/zencore/filesystem.cpp
@@ -891,8 +891,13 @@ MoveToFile(std::filesystem::path Path, IoBuffer Data)
return false;
}
#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
- std::filesystem::path SourcePath = PathFromHandle(FileRef.FileHandle);
- int Ret = link(SourcePath.c_str(), Path.c_str());
+ std::error_code Ec;
+ std::filesystem::path SourcePath = PathFromHandle(FileRef.FileHandle, Ec);
+ if (Ec)
+ {
+ return false;
+ }
+ int Ret = link(SourcePath.c_str(), Path.c_str());
if (Ret < 0)
{
int32_t err = errno;
@@ -1409,18 +1414,6 @@ PathFromHandle(void* NativeHandle, std::error_code& Ec)
#endif // ZEN_PLATFORM_WINDOWS
}
-std::filesystem::path
-PathFromHandle(void* NativeHandle)
-{
- std::error_code Ec;
- std::filesystem::path Result = PathFromHandle(NativeHandle, Ec);
- if (Ec)
- {
- throw std::system_error(Ec, fmt::format("failed to get path from file handle '{}'", NativeHandle));
- }
- return Result;
-}
-
uint64_t
FileSizeFromHandle(void* NativeHandle)
{
@@ -1742,7 +1735,9 @@ TEST_CASE("filesystem")
Handle = (void*)uintptr_t(Fd);
# endif
- auto FromHandle = PathFromHandle((void*)uintptr_t(Handle));
+ std::error_code Ec;
+ auto FromHandle = PathFromHandle((void*)uintptr_t(Handle), Ec);
+ CHECK(!Ec);
CHECK(equivalent(FromHandle, BinPath));
# if ZEN_PLATFORM_WINDOWS