#include "./stacked.hpp" #include #include "../detect.hpp" namespace mijin { // // internal defines // // // internal constants // // // internal types // // // internal variables // // // internal functions // // // public functions // std::vector StackedFileSystemAdapter::listFiles(PathView folder) { std::vector files; for (auto& adapter : adapters_) { for (const FolderEntry& entry : adapter->listFiles(folder)) { auto it = std::ranges::find_if(files, [&](const FolderEntry& existing) { return existing.path == entry.path; }); if (it == files.end()) { files.push_back(entry); } } } return files; } FileInfo StackedFileSystemAdapter::getFileInfo(PathView file) { for (auto& adapter : adapters_) { FileInfo fileInfo = adapter->getFileInfo(file); if (fileInfo.exists) { return fileInfo; } } return {}; } Optional StackedFileSystemAdapter::getNativePath(PathView file) { for (auto& adapter : adapters_) { Optional result = adapter->getNativePath(file); if (!result.empty()) { return result; } } return NULL_OPTIONAL; } StreamError StackedFileSystemAdapter::open(PathView path, FileOpenMode mode, std::unique_ptr& outStream) { // try to open existing files first for (auto& adapter : adapters_) { const FileInfo fileInfo = adapter->getFileInfo(path); if (fileInfo.exists) { return adapter->open(path, mode, outStream); } } // if that doesn't work we attempt to write, try creating it if (mode == FileOpenMode::WRITE || mode == FileOpenMode::READ_WRITE) { for (auto& adapter : adapters_) { const StreamError error = adapter->open(path, mode, outStream); if (error == StreamError::SUCCESS) { return StreamError::SUCCESS; } } } return StreamError::IO_ERROR; } void StackedFileSystemAdapter::getAllPaths(PathView path, std::vector& outPaths) { for (auto& adapter : adapters_) { adapter->getAllPaths(path, outPaths); } } } // namespace mijin