From 66c7958084601f30fb7b5cc2cd5ba58d39213b26 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 7 Mar 2021 15:39:36 +0100 Subject: [PATCH] minor filesystem fixups --- framework/filesystem/src/mm/fs_const_archiver.cpp | 4 +++- framework/filesystem/src/mm/services/filesystem.cpp | 6 ++++-- framework/filesystem/test/filesystem_tests.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/filesystem/src/mm/fs_const_archiver.cpp b/framework/filesystem/src/mm/fs_const_archiver.cpp index 4909ad3..24b59c0 100644 --- a/framework/filesystem/src/mm/fs_const_archiver.cpp +++ b/framework/filesystem/src/mm/fs_const_archiver.cpp @@ -186,12 +186,14 @@ PHYSFS_Io* FSConstArchiver::createIO(const char* filename, PHYSFS_uint64 pos) { } bool FSConstArchiver::pathIsDir(const char* path) { + // TODO: fix leading '/' + std::string_view pstr {path}; //for (auto&[str, data] : _storage) { for (auto& it : _storage) { // stats_with c++20 <.< - if (it.first.compare(0, pstr.size(), pstr) == 0) { + if (it.first.compare(0, pstr.size(), pstr) == 0 && it.first.size() != pstr.size()) { return true; } } diff --git a/framework/filesystem/src/mm/services/filesystem.cpp b/framework/filesystem/src/mm/services/filesystem.cpp index 968820b..dfc04b3 100644 --- a/framework/filesystem/src/mm/services/filesystem.cpp +++ b/framework/filesystem/src/mm/services/filesystem.cpp @@ -296,11 +296,13 @@ nlohmann::json FilesystemService::readJson(fs_file_t file) const { std::string buffer; readString(file, buffer); - return nlohmann::json::parse(buffer); + // disable exeptions + // TODO: use callback instead of readString() + return nlohmann::json::parse(buffer, nullptr, false); } nlohmann::json FilesystemService::readJson(const char* filepath) const { - if (!exists(filepath)) { + if (!isFile(filepath)) { return {}; } diff --git a/framework/filesystem/test/filesystem_tests.cpp b/framework/filesystem/test/filesystem_tests.cpp index 135b38e..ca9fdd5 100644 --- a/framework/filesystem/test/filesystem_tests.cpp +++ b/framework/filesystem/test/filesystem_tests.cpp @@ -219,7 +219,7 @@ TEST(fs_service_system, read_const_json) { ASSERT_TRUE(j.empty()); } - FS_CONST_MOUNT_FILE("json/file1.json", + FS_CONST_MOUNT_FILE("/json/file1.json", R"({ "answer": { "everything": 42