diff options
| author | Dan Engelbrecht <[email protected]> | 2024-10-16 09:49:55 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-10-16 09:49:55 +0200 |
| commit | b254f75968e1a5692fa872fcfda5eaa1a0ed561d (patch) | |
| tree | 968e5fc30e37295a4c5767d5c290016116e196ab /src/zenutil | |
| parent | upload linux mac exe to sentry (#196) (diff) | |
| download | zen-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/zenutil')
| -rw-r--r-- | src/zenutil/basicfile.cpp | 17 | ||||
| -rw-r--r-- | src/zenutil/include/zenutil/basicfile.h | 2 | ||||
| -rw-r--r-- | src/zenutil/packageformat.cpp | 9 |
3 files changed, 19 insertions, 9 deletions
diff --git a/src/zenutil/basicfile.cpp b/src/zenutil/basicfile.cpp index 575d153b2..73f27b587 100644 --- a/src/zenutil/basicfile.cpp +++ b/src/zenutil/basicfile.cpp @@ -858,13 +858,16 @@ TEST_CASE("TemporaryFile") SUBCASE("DeleteOnClose") { - TemporaryFile TmpFile; - std::error_code Ec; - TmpFile.CreateTemporary(std::filesystem::current_path(), Ec); - CHECK(!Ec); - CHECK(std::filesystem::exists(TmpFile.GetPath())); - TmpFile.Close(); - CHECK(std::filesystem::exists(TmpFile.GetPath()) == false); + std::filesystem::path Path; + { + TemporaryFile TmpFile; + std::error_code Ec; + TmpFile.CreateTemporary(std::filesystem::current_path(), Ec); + CHECK(!Ec); + Path = TmpFile.GetPath(); + CHECK(std::filesystem::exists(Path)); + } + CHECK(std::filesystem::exists(Path) == false); } SUBCASE("MoveIntoPlace") diff --git a/src/zenutil/include/zenutil/basicfile.h b/src/zenutil/include/zenutil/basicfile.h index 674457196..03c5605df 100644 --- a/src/zenutil/include/zenutil/basicfile.h +++ b/src/zenutil/include/zenutil/basicfile.h @@ -96,7 +96,6 @@ public: TemporaryFile(const TemporaryFile&) = delete; TemporaryFile& operator=(const TemporaryFile&) = delete; - void Close(); void CreateTemporary(std::filesystem::path TempDirName, std::error_code& Ec); void MoveTemporaryIntoPlace(std::filesystem::path FinalFileName, std::error_code& Ec); const std::filesystem::path& GetPath() const { return m_TempPath; } @@ -105,6 +104,7 @@ public: static void SafeWriteFile(const std::filesystem::path& Path, MemoryView Data, std::error_code& OutEc); private: + void Close(); std::filesystem::path m_TempPath; using BasicFile::Open; diff --git a/src/zenutil/packageformat.cpp b/src/zenutil/packageformat.cpp index 8087b7564..579e0d13c 100644 --- a/src/zenutil/packageformat.cpp +++ b/src/zenutil/packageformat.cpp @@ -126,7 +126,14 @@ IsLocalRef(tsl::robin_map<void*, std::string>& FileNameMap, if (UseFilePath) { ExtendablePathBuilder<256> LocalRefFile; - LocalRefFile.Append(std::filesystem::absolute(PathFromHandle(Ref.FileHandle))); + std::error_code Ec; + std::filesystem::path FilePath = PathFromHandle(Ref.FileHandle, Ec); + if (Ec) + { + ZEN_WARN("Failed to get path for file handle {} in IsLocalRef check, reason '{}'", Ref.FileHandle, Ec.message()); + return false; + } + LocalRefFile.Append(std::filesystem::absolute(FilePath)); Path8 = LocalRefFile.ToUtf8(); } FileNameMap.insert_or_assign(Ref.FileHandle, Path8); |