From fffbd7b7d909b7ada822baba5d8aa1b2a76f9837 Mon Sep 17 00:00:00 2001 From: bugdea1er Date: Thu, 18 Dec 2025 22:19:07 +0300 Subject: [PATCH] Return canonical path from `directory::path` --- include/tmp/directory | 4 ++-- src/create_directory.cpp | 2 +- tests/directory.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/tmp/directory b/include/tmp/directory index 8ab804f..672f369 100644 --- a/include/tmp/directory +++ b/include/tmp/directory @@ -76,13 +76,13 @@ public: } /// Returns the path of this directory - /// @returns The full path of this directory + /// @returns The canonical path of this directory operator const std::filesystem::path&() const noexcept { return pathobject; } /// Returns the path of this directory - /// @returns The full path of this directory + /// @returns The canonical path of this directory const std::filesystem::path& path() const noexcept { return pathobject; } diff --git a/src/create_directory.cpp b/src/create_directory.cpp index a953f52..798a902 100644 --- a/src/create_directory.cpp +++ b/src/create_directory.cpp @@ -90,6 +90,6 @@ fs::path create_directory(std::string_view prefix) { throw fs::filesystem_error("Cannot create a temporary directory", ec); } - return path; + return fs::canonical(path); } } // namespace tmp::detail diff --git a/tests/directory.cpp b/tests/directory.cpp index 1b4a435..16a605a 100644 --- a/tests/directory.cpp +++ b/tests/directory.cpp @@ -30,6 +30,8 @@ TEST(directory, create_with_prefix) { EXPECT_TRUE(fs::is_directory(tmpdir)); EXPECT_TRUE(fs::equivalent(parent, fs::temp_directory_path())); + EXPECT_EQ(fs::canonical(tmpdir), tmpdir.path()); + #ifdef _WIN32 constexpr std::wstring_view actual_prefix = L"com.github.bugdea1er.tmp."; #else