From 83a46cae15b07654ea806f94661d9f3d3c497948 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Tue, 23 Jul 2024 20:16:12 +0200 Subject: [PATCH] Fixed other functions in RelativeFileSystemAdapter. --- source/mijin/virtual_filesystem/relative.hpp | 27 ++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/source/mijin/virtual_filesystem/relative.hpp b/source/mijin/virtual_filesystem/relative.hpp index 1aa0245..f13d18d 100644 --- a/source/mijin/virtual_filesystem/relative.hpp +++ b/source/mijin/virtual_filesystem/relative.hpp @@ -42,6 +42,8 @@ public: std::vector listFiles(const fs::path& folder) override; FileInfo getFileInfo(const fs::path& file) override; StreamError open(const fs::path& path, FileOpenMode mode, std::unique_ptr& outStream) override; +private: + fs::path appendPath(const fs::path& other) const noexcept; }; // @@ -64,15 +66,8 @@ template std::vector RelativeFileSystemAdapter::listFiles(const fs::path& folder) { std::vector result; - fs::path combinedPath = root_; - if (folder.is_absolute()) { - combinedPath += folder; - } - else { - combinedPath /= folder; - } - result = wrapped_.listFiles(combinedPath); + result = wrapped_.listFiles(appendPath(folder)); for (FileInfo& fileInfo : result) { fileInfo.path = "/" / fileInfo.path.lexically_relative(root_); } @@ -82,15 +77,27 @@ std::vector RelativeFileSystemAdapter::listFiles(const fs::p template FileInfo RelativeFileSystemAdapter::getFileInfo(const fs::path& file) { - return wrapped_.getFileInfo(root_ / file); + return wrapped_.getFileInfo(appendPath(file)); } template StreamError RelativeFileSystemAdapter::open(const fs::path& path, FileOpenMode mode, std::unique_ptr& outStream) { - return wrapped_.open(root_ / path, mode, outStream); + return wrapped_.open(appendPath(path), mode, outStream); } +template +fs::path RelativeFileSystemAdapter::appendPath(const fs::path& other) const noexcept +{ + fs::path combinedPath = root_; + if (other.is_absolute()) { + combinedPath += other; + } + else { + combinedPath /= other; + } + return combinedPath; +} } // namespace mijin #endif // !defined(MIJIN_VIRTUAL_FILESYSTEM_RELATIVE_HPP_INCLUDED)