summaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-28 20:13:55 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-28 20:13:55 +0300
commit993e6f9b9606a71ad35302f0767017fd426c1d0e (patch)
tree13a8bc658412348d8ea2d248b8d6b6a684f1e541 /src/fs
parentc33ecc43f775eebae66e5ad0dc5f9588162b3783 (diff)
downloadmanaplus-993e6f9b9606a71ad35302f0767017fd426c1d0e.tar.gz
manaplus-993e6f9b9606a71ad35302f0767017fd426c1d0e.tar.bz2
manaplus-993e6f9b9606a71ad35302f0767017fd426c1d0e.tar.xz
manaplus-993e6f9b9606a71ad35302f0767017fd426c1d0e.zip
Fix files enumeration in root directory in VirtFsZip.
Also add tests for same for other VirtFs functions.
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/virtfs_unittest.cc56
-rw-r--r--src/fs/virtfsphys_unittest.cc55
-rw-r--r--src/fs/virtfszip.cpp48
-rw-r--r--src/fs/virtfszip_unittest.cc51
4 files changed, 202 insertions, 8 deletions
diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc
index 5b9da2394..7e079e212 100644
--- a/src/fs/virtfs_unittest.cc
+++ b/src/fs/virtfs_unittest.cc
@@ -106,6 +106,17 @@ static void removeTemp(StringVect &restrict list)
}
}
+static bool inList(VirtList *list,
+ const std::string &name)
+{
+ FOR_EACH (StringVectCIter, it, list->names)
+ {
+ if (*it == name)
+ return true;
+ }
+ return false;
+}
+
TEST_CASE("VirtFs enumerateFiles1")
{
logger = new Logger;
@@ -163,6 +174,51 @@ TEST_CASE("VirtFs enumerateFiles2")
delete2(logger);
}
+TEST_CASE("VirtFs enumerateFiles3")
+{
+ logger = new Logger;
+
+ VirtFs::addZipToSearchPath("data/test/test.zip",
+ Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip",
+ Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFs::enumerateFiles("/");
+ REQUIRE(list->names.size() == 1);
+ REQUIRE(inList(list, "dir"));
+ VirtFs::freeList(list);
+
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
+ delete2(logger);
+}
+
+TEST_CASE("VirtFs enumerateFiles4")
+{
+ logger = new Logger;
+
+ VirtFs::addZipToSearchPath("data/test/test2.zip",
+ Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test2.zip",
+ Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFs::enumerateFiles("/");
+ REQUIRE(list->names.size() == 4);
+ REQUIRE(inList(list, "dir"));
+ REQUIRE(inList(list, "dir2"));
+ REQUIRE(inList(list, "test.txt"));
+ REQUIRE(inList(list, "units.xml"));
+ VirtFs::freeList(list);
+
+ VirtFs::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
TEST_CASE("VirtFs isDirectory")
{
logger = new Logger();
diff --git a/src/fs/virtfsphys_unittest.cc b/src/fs/virtfsphys_unittest.cc
index a70402668..d9821d350 100644
--- a/src/fs/virtfsphys_unittest.cc
+++ b/src/fs/virtfsphys_unittest.cc
@@ -174,6 +174,61 @@ TEST_CASE("VirtFsPhys enumerateFiles2")
delete2(logger);
}
+static bool inList(VirtList *list,
+ const std::string &name)
+{
+ FOR_EACH (StringVectCIter, it, list->names)
+ {
+ if (*it == name)
+ return true;
+ }
+ return false;
+}
+
+TEST_CASE("VirtFsPhys enumerateFiles3")
+{
+ VirtFsPhys::initFuncs();
+ logger = new Logger;
+
+ VirtFsPhys::addZipToSearchPath("data/test/test.zip",
+ Append_false);
+ VirtFsPhys::addZipToSearchPath("../data/test/test.zip",
+ Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFsPhys::enumerateFiles("/");
+ REQUIRE(inList(list, "units.xml") == false);
+ REQUIRE(inList(list, "test.txt") == false);
+ VirtFsPhys::freeList(list);
+
+ VirtFsPhys::removeZipFromSearchPath("data/test/test.zip");
+ VirtFsPhys::removeZipFromSearchPath("../data/test/test.zip");
+ delete2(logger);
+}
+
+TEST_CASE("VirtFsPhys enumerateFiles4")
+{
+ VirtFsPhys::initFuncs();
+ logger = new Logger;
+
+ VirtFsPhys::addZipToSearchPath("data/test/test2.zip",
+ Append_false);
+ VirtFsPhys::addZipToSearchPath("../data/test/test2.zip",
+ Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFsPhys::enumerateFiles("/");
+ REQUIRE(inList(list, "units.xml") == true);
+ REQUIRE(inList(list, "test.txt") == true);
+ VirtFsPhys::freeList(list);
+
+ VirtFsPhys::removeZipFromSearchPath("data/test/test2.zip");
+ VirtFsPhys::removeZipFromSearchPath("../data/test/test2.zip");
+ delete2(logger);
+}
+
TEST_CASE("VirtFsPhys isDirectory")
{
VirtFsPhys::initFuncs();
diff --git a/src/fs/virtfszip.cpp b/src/fs/virtfszip.cpp
index 35b94c780..dc8223b6f 100644
--- a/src/fs/virtfszip.cpp
+++ b/src/fs/virtfszip.cpp
@@ -274,17 +274,17 @@ namespace VirtFsZip
if (findLast(dirName, std::string(dirSeparator)) == false)
dirName += dirSeparator;
StringVect &names = list->names;
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
+ if (dirName == "/")
{
- VirtZipEntry *const entry = *it;
- FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
- it2,
- entry->mHeaders)
+ FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
{
- ZipLocalHeader *const header = *it2;
- std::string fileName = header->fileName;
- if (findCutFirst(fileName, dirName) == true)
+ VirtZipEntry *const entry = *it;
+ FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
+ it2,
+ entry->mHeaders)
{
+ ZipLocalHeader *const header = *it2;
+ std::string fileName = header->fileName;
// skip subdirs from enumeration
const size_t idx = fileName.find(dirSeparator);
if (idx != std::string::npos)
@@ -303,6 +303,38 @@ namespace VirtFsZip
}
}
}
+ else
+ {
+ FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
+ {
+ VirtZipEntry *const entry = *it;
+ FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
+ it2,
+ entry->mHeaders)
+ {
+ ZipLocalHeader *const header = *it2;
+ std::string fileName = header->fileName;
+ if (findCutFirst(fileName, dirName) == true)
+ {
+ // skip subdirs from enumeration
+ const size_t idx = fileName.find(dirSeparator);
+ if (idx != std::string::npos)
+ fileName.erase(idx);
+ bool found(false);
+ FOR_EACH (StringVectCIter, itn, names)
+ {
+ if (*itn == fileName)
+ {
+ found = true;
+ break;
+ }
+ }
+ if (found == false)
+ names.push_back(fileName);
+ }
+ }
+ }
+ }
return list;
}
diff --git a/src/fs/virtfszip_unittest.cc b/src/fs/virtfszip_unittest.cc
index 3eb8a2357..4840a23a9 100644
--- a/src/fs/virtfszip_unittest.cc
+++ b/src/fs/virtfszip_unittest.cc
@@ -397,6 +397,57 @@ TEST_CASE("VirtFsZip enumerateFiles2")
delete2(logger);
}
+TEST_CASE("VirtFsZip enumerateFiles3")
+{
+ VirtFsZip::init();
+ logger = new Logger;
+ std::string name("data/test/test.zip");
+ std::string prefix("data\\test/");
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+
+ VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
+ Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFsZip::enumerateFiles("/");
+ REQUIRE(list->names.size() == 1);
+ REQUIRE(inList(list, "dir"));
+ VirtFsZip::freeList(list);
+
+ VirtFsZip::removeFromSearchPathSilent(prefix + "test.zip");
+ VirtFsZip::deinit();
+ delete2(logger);
+}
+
+TEST_CASE("VirtFsZip enumerateFiles4")
+{
+ VirtFsZip::init();
+ logger = new Logger;
+ std::string name("data/test/test.zip");
+ std::string prefix("data\\test/");
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+
+ VirtFsZip::addToSearchPathSilent(prefix + "test2.zip",
+ Append_false);
+
+ VirtList *list = nullptr;
+
+ list = VirtFsZip::enumerateFiles("/");
+ REQUIRE(list->names.size() == 4);
+ REQUIRE(inList(list, "dir"));
+ REQUIRE(inList(list, "dir2"));
+ REQUIRE(inList(list, "test.txt"));
+ REQUIRE(inList(list, "units.xml"));
+ VirtFsZip::freeList(list);
+
+ VirtFsZip::removeFromSearchPathSilent(prefix + "test2.zip");
+ VirtFsZip::deinit();
+ delete2(logger);
+}
+
TEST_CASE("VirtFsZip isDirectory")
{
VirtFsZip::init();