#include "./tox_ft_filesystem.hpp" #include #include #include #include namespace Backends { ToxFTFilesystem::ToxFTFilesystem( ObjectStore2& os ) : StorageBackendI::StorageBackendI(os) { } ToxFTFilesystem::~ToxFTFilesystem(void) { } ObjectHandle ToxFTFilesystem::newObject(ByteSpan id) { ObjectHandle o{_os.registry(), _os.registry().create()}; o.emplace(this); o.emplace(std::vector{id}); //o.emplace(object_file_path.generic_u8string()); _os.throwEventConstruct(o); return o; } std::unique_ptr ToxFTFilesystem::file2(Object ov, FILE2_FLAGS flags) { if (flags & FILE2_RAW) { std::cerr << "TFTF error: does not support raw modes\n"; return nullptr; } if (flags == FILE2_NONE) { std::cerr << "TFTF error: no file mode set\n"; assert(false); return nullptr; } if (flags & FILE2_WRITE) { std::cerr << "TFTF error: opening file in write mode not supported\n"; } ObjectHandle o{_os.registry(), ov}; if (!static_cast(o)) { return nullptr; } // will this do if we go and support enc? // use ObjComp::Ephemeral::FilePath instead?? if (!o.all_of()) { return nullptr; } const auto& file_path = o.get().file_path; if (file_path.empty()) { return nullptr; } // read only auto res = std::make_unique(file_path); if (!res || !res->isGood()) { std::cerr << "TFTF error: failed constructing file '" << file_path << "'\n"; return nullptr; } return res; } } // Backends