#include "./stacked.hpp" #include namespace mijin { // // internal defines // // // internal constants // // // internal types // // // internal variables // // // internal functions // // // public functions // std::vector StackedFileSystemAdapter::getRoots() { std::vector roots; for (auto& adapter : adapters_) { for (const fs::path& root : adapter->getRoots()) { auto it = std::find(roots.begin(), roots.end(), root); if (it == roots.end()) { roots.push_back(root); } } } return roots; } fs::path StackedFileSystemAdapter::getHomeFolder() { if (adapters_.empty()) { return fs::path(); } return adapters_.front()->getHomeFolder(); } std::vector StackedFileSystemAdapter::listFiles(const fs::path& folder) { std::vector files; for (auto& adapter : adapters_) { for (const FileInfo& file : adapter->listFiles(folder)) { auto it = std::find_if(files.begin(), files.end(), [&](const FileInfo& existing) { return existing.path == file.path; }); if (it == files.end()) { files.push_back(file); } } } return files; } FileInfo StackedFileSystemAdapter::getFileInfo(const fs::path& file) { for (auto& adapter : adapters_) { FileInfo fileInfo = adapter->getFileInfo(file); if (fileInfo.exists) { return fileInfo; } } return {}; } StreamError StackedFileSystemAdapter::open(const fs::path& path, FileOpenMode mode, std::unique_ptr& outStream) { for (auto& adapter : adapters_) { FileInfo fileInfo = adapter->getFileInfo(path); if (fileInfo.exists) { return adapter->open(path, mode, outStream); } } return StreamError::IO_ERROR; } } // namespace mijin