diff options
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r-- | src/fs/virtfs/virtfsdir_unittest.cc | 14 | ||||
-rw-r--r-- | src/fs/virtfs/virtfszip.cpp | 43 | ||||
-rw-r--r-- | src/fs/virtfs/virtfszip.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/virtfszip_unittest.cc | 4 |
4 files changed, 55 insertions, 8 deletions
diff --git a/src/fs/virtfs/virtfsdir_unittest.cc b/src/fs/virtfs/virtfsdir_unittest.cc index ad55acf2e..0a39dbdb4 100644 --- a/src/fs/virtfs/virtfsdir_unittest.cc +++ b/src/fs/virtfs/virtfsdir_unittest.cc @@ -247,6 +247,9 @@ TEST_CASE("VirtFsDir exists") Append_false, SkipError_false); + REQUIRE(VirtFsDir::exists("test") == true); + REQUIRE(VirtFsDir::exists("test/dir1")); + REQUIRE(VirtFsDir::exists("test/dir") == false); REQUIRE(VirtFsDir::exists("test//units.xml") == true); REQUIRE(VirtFsDir::exists("test/\\units123.xml") == false); REQUIRE(VirtFsDir::exists("tesQ/units.xml") == false); @@ -259,6 +262,9 @@ TEST_CASE("VirtFsDir exists") Append_false, SkipError_false); + REQUIRE(VirtFsDir::exists("test") == true); + REQUIRE(VirtFsDir::exists("test/dir1")); + REQUIRE(VirtFsDir::exists("test/dir") == false); REQUIRE(VirtFsDir::exists("test\\units.xml") == true); REQUIRE(VirtFsDir::exists("test/units123.xml") == false); REQUIRE(VirtFsDir::exists("tesQ/units.xml") == false); @@ -267,6 +273,9 @@ TEST_CASE("VirtFsDir exists") VirtFsDir::removeFromSearchPathSilent("data/test"); VirtFsDir::removeFromSearchPathSilent("../data/test"); + REQUIRE(VirtFsDir::exists("test") == true); + REQUIRE(VirtFsDir::exists("test/dir1")); + REQUIRE(VirtFsDir::exists("test/dir") == false); REQUIRE(VirtFsDir::exists("test\\units.xml") == true); REQUIRE(VirtFsDir::exists("test/units123.xml") == false); REQUIRE(VirtFsDir::exists("tesQ/units.xml") == false); @@ -430,6 +439,11 @@ TEST_CASE("VirtFsDir enumerateFiles1") REQUIRE(list->names.size() == cnt2); VirtFsDir::freeList(list); + VirtFsDir::permitLinks(true); + list = VirtFsDir::enumerateFiles("test/units.xml"); + REQUIRE(list->names.size() == 0); + VirtFsDir::freeList(list); + VirtFsDir::permitLinks(false); list = VirtFsDir::enumerateFiles("test\\"); removeTemp(list->names); diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp index c4ce6f9e8..425883f6d 100644 --- a/src/fs/virtfs/virtfszip.cpp +++ b/src/fs/virtfs/virtfszip.cpp @@ -67,7 +67,34 @@ namespace VirtFsZip entry->mHeaders) { if ((*it2)->fileName == filename) - return *it2;; + return *it2; + } + } + return nullptr; + } + + VirtZipEntry *searchZipEntryByNameWithDir(const std::string &restrict + filename) + { + std::string dirName = filename; + if (findLast(dirName, std::string(dirSeparator)) == false) + dirName += dirSeparator; + FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries) + { + VirtZipEntry *const entry = *it; + FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator, + it2, + entry->mHeaders) + { + if ((*it2)->fileName == filename) + return entry; + } + FOR_EACH (std::vector<std::string>::const_iterator, + it2, + entry->mDirs) + { + if (*it2 == dirName) + return entry; } } return nullptr; @@ -246,9 +273,10 @@ namespace VirtFsZip std::string getRealDirInternal(const std::string &filename) { - ZipLocalHeader *restrict const header = searchHeaderByName(filename); - if (header != nullptr) - return header->zipEntry->mArchiveName; + VirtZipEntry *restrict const entry = searchZipEntryByNameWithDir( + filename); + if (entry != nullptr) + return entry->mArchiveName; return std::string(); } @@ -261,10 +289,9 @@ namespace VirtFsZip name.c_str()); return false; } - ZipLocalHeader *restrict const header = searchHeaderByName(name); - if (header != nullptr) - return true; - return false; + VirtZipEntry *restrict const entry = searchZipEntryByNameWithDir( + name); + return entry != nullptr; } VirtList *enumerateFiles(std::string dirName) diff --git a/src/fs/virtfs/virtfszip.h b/src/fs/virtfs/virtfszip.h index c1ed7b05c..3048e9d0d 100644 --- a/src/fs/virtfs/virtfszip.h +++ b/src/fs/virtfs/virtfszip.h @@ -40,6 +40,8 @@ namespace VirtFsZip VirtZipEntry *searchEntryByArchive(const std::string &restrict archiveName); ZipLocalHeader *searchHeaderByName(const std::string &restrict filename); + VirtZipEntry *searchZipEntryByNameWithDir(const std::string &restrict + filename); bool addToSearchPath(std::string newDir, const Append append); bool addToSearchPathSilent(std::string newDir, diff --git a/src/fs/virtfs/virtfszip_unittest.cc b/src/fs/virtfs/virtfszip_unittest.cc index 7ac442c78..0cde2c80f 100644 --- a/src/fs/virtfs/virtfszip_unittest.cc +++ b/src/fs/virtfs/virtfszip_unittest.cc @@ -256,6 +256,7 @@ TEST_CASE("VirtFsZip exists") REQUIRE(VirtFsZip::exists("units1.xml") == false); REQUIRE(VirtFsZip::exists("dir/hide.png") == true); REQUIRE(VirtFsZip::exists("dir/brimmedhat.png") == false); + REQUIRE(VirtFsZip::exists("dir\\1")); VirtFsZip::addToSearchPathSilent("data/test/test.zip", Append_false); @@ -268,6 +269,7 @@ TEST_CASE("VirtFsZip exists") REQUIRE(VirtFsZip::exists("units1.xml") == false); REQUIRE(VirtFsZip::exists("dir/hide.png") == true); REQUIRE(VirtFsZip::exists("dir/brimmedhat.png") == true); + REQUIRE(VirtFsZip::exists("dir\\1")); VirtFsZip::removeFromSearchPathSilent("data/test/test2.zip"); VirtFsZip::removeFromSearchPathSilent("../data/test/test2.zip"); @@ -278,6 +280,7 @@ TEST_CASE("VirtFsZip exists") REQUIRE(VirtFsZip::exists("units1.xml") == false); REQUIRE(VirtFsZip::exists("dir/\\/hide.png") == true); REQUIRE(VirtFsZip::exists("dir/brimmedhat.png") == true); + REQUIRE(VirtFsZip::exists("dir\\1") == false); REQUIRE_THROWS(VirtFsZip::exists("test/../units.xml")); @@ -299,6 +302,7 @@ TEST_CASE("VirtFsZip getRealDir") REQUIRE(VirtFsZip::getRealDir(".") == ""); REQUIRE(VirtFsZip::getRealDir("..") == ""); REQUIRE(VirtFsZip::getRealDir("test.txt") == prefix + "test2.zip"); + REQUIRE(VirtFsZip::getRealDir("dir/1") == prefix + "test2.zip"); REQUIRE(VirtFsZip::getRealDir("dir\\dye.png") == prefix + "test2.zip"); REQUIRE(VirtFsZip::getRealDir("zzz") == ""); |