Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ namespace zenkit {
continue;
}

if (context->type() != VfsNodeType::DIRECTORY) return nullptr;

auto name = path.substr(0, next);
context = context->child(name);

Expand Down Expand Up @@ -533,7 +535,7 @@ namespace zenkit {
auto childName = path.substr(lastSlash + 1);

VfsNode* pNode = this->resolve(parentPath);
if (pNode == nullptr) return false;
if (pNode == nullptr || pNode->type() != VfsNodeType::DIRECTORY) return false;
return pNode->remove(childName);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/TestVfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ TEST_SUITE("Vfs") {
check_vfs(vdf);
}

TEST_CASE("Vfs.resolve(through_file)") {
auto vdf = zenkit::Vfs {};
vdf.mount_disk("./samples/basic.vdf");

CHECK_EQ(vdf.resolve("config.yml/nonexistent"), nullptr);
CHECK_EQ(vdf.resolve("licenses/gpl/lgpl-3.0.md/nonexistent"), nullptr);
CHECK_THROWS_AS(vdf.mount(zenkit::VfsNode::directory("dir"), "config.yml/nonexistent"),
zenkit::VfsNotFoundError);
}

TEST_CASE("Vfs.remove(through_file)") {
auto vdf = zenkit::Vfs {};
vdf.mount_disk("./samples/basic.vdf");

CHECK_FALSE(vdf.remove("config.yml/nonexistent"));

auto const* config_yml = vdf.resolve("config.yml");
REQUIRE_NE(config_yml, nullptr);
CHECK(config_yml->type() == zenkit::VfsNodeType::FILE);

CHECK(vdf.remove("licenses/gpl/lgpl-3.0.md"));
CHECK_EQ(vdf.resolve("licenses/gpl/lgpl-3.0.md"), nullptr);
}

#ifdef _ZK_WITH_ZIPPED_VDF
TEST_CASE("Vfs.mount_disk(basic_zipped)") {
auto vdf = zenkit::Vfs {};
Expand Down
Loading