minor filesystem fixups

This commit is contained in:
Green Sky 2021-03-07 15:39:36 +01:00
parent 4f859bad2e
commit 66c7958084
3 changed files with 8 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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 {};
}

View File

@ -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