diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-05-16 16:28:54 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-05-16 16:28:54 +0300 |
commit | 0a849f982988cbd7c7afdedccb210bada702238b (patch) | |
tree | 93fe4838817db6e57c7dbc364dd347d275c67937 /src/fs/virtfs | |
parent | b60b3123345a619aab656c1c361c2c8c42e6455c (diff) | |
download | manaverse-0a849f982988cbd7c7afdedccb210bada702238b.tar.gz manaverse-0a849f982988cbd7c7afdedccb210bada702238b.tar.bz2 manaverse-0a849f982988cbd7c7afdedccb210bada702238b.tar.xz manaverse-0a849f982988cbd7c7afdedccb210bada702238b.zip |
Add subdir support in VirtFs::isDirectory.
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r-- | src/fs/virtfs/fsdir.cpp | 4 | ||||
-rw-r--r-- | src/fs/virtfs/fsdir.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/fsfuncs.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/fszip.cpp | 5 | ||||
-rw-r--r-- | src/fs/virtfs/fszip.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/virtfs1_unittest.cc | 69 |
6 files changed, 78 insertions, 6 deletions
diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp index 7556a395c..5d6f97d8e 100644 --- a/src/fs/virtfs/fsdir.cpp +++ b/src/fs/virtfs/fsdir.cpp @@ -231,10 +231,10 @@ namespace FsDir } bool isDirectory(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, bool &isDirFlag) { - std::string path = entry->root + dirName; + std::string path = entry->root + entry->subDir + dirName; struct stat statbuf; if (stat(path.c_str(), &statbuf) == 0) diff --git a/src/fs/virtfs/fsdir.h b/src/fs/virtfs/fsdir.h index 01c225f95..d797a78ea 100644 --- a/src/fs/virtfs/fsdir.h +++ b/src/fs/virtfs/fsdir.h @@ -68,7 +68,7 @@ namespace FsDir const std::string &dirName, StringVect &names); bool isDirectory(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, bool &isDirFlag); bool isSymbolicLink(std::string name); void freeList(List *restrict const handle); diff --git a/src/fs/virtfs/fsfuncs.h b/src/fs/virtfs/fsfuncs.h index 6b5647bcd..4f409cc72 100644 --- a/src/fs/virtfs/fsfuncs.h +++ b/src/fs/virtfs/fsfuncs.h @@ -101,7 +101,7 @@ struct FsFuncs final const std::string &dirName, StringVect &names); bool (*isDirectory) (FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, bool &isDirFlag); File *(*openRead) (FsEntry *restrict const entry, const std::string &filename); diff --git a/src/fs/virtfs/fszip.cpp b/src/fs/virtfs/fszip.cpp index 5118ec93c..e7fab595f 100644 --- a/src/fs/virtfs/fszip.cpp +++ b/src/fs/virtfs/fszip.cpp @@ -500,10 +500,13 @@ namespace FsZip } bool isDirectory(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, bool &isDirFlag) { ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry); + std::string subDir = zipEntry->subDir; + if (subDir != dirSeparator) + dirName = pathJoin(subDir, dirName); FOR_EACH (std::vector<std::string>::const_iterator, it2, zipEntry->mDirs) diff --git a/src/fs/virtfs/fszip.h b/src/fs/virtfs/fszip.h index 0abe07807..cd847b3b0 100644 --- a/src/fs/virtfs/fszip.h +++ b/src/fs/virtfs/fszip.h @@ -55,7 +55,7 @@ namespace FsZip const std::string &dirName, StringVect &names); bool isDirectory(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, bool &isDirFlag); void freeList(List *restrict const handle); File *openRead(FsEntry *restrict const entry, diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc index 57d82e9af..ae3c00118 100644 --- a/src/fs/virtfs/virtfs1_unittest.cc +++ b/src/fs/virtfs/virtfs1_unittest.cc @@ -2004,6 +2004,75 @@ TEST_CASE("VirtFs1 isDirectory2") delete2(logger); } +TEST_CASE("VirtFs1 isDirectory3") +{ + VirtFs::init("."); + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../" + prefix; + + VirtFs::mountDir2(prefix + "data", + "test", + Append_false); + + REQUIRE(VirtFs::isDirectory("units.xml") == false); + REQUIRE(VirtFs::isDirectory("units.xml/") == false); + REQUIRE(VirtFs::isDirectory("units123.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ//units.xml") == false); + REQUIRE(VirtFs::isDirectory("test") == false); + REQUIRE(VirtFs::isDirectory("dir1") == true); + REQUIRE(VirtFs::isDirectory("dir2//") == true); + REQUIRE(VirtFs::isDirectory("test/dir1") == false); + REQUIRE(VirtFs::isDirectory("testQ") == false); + REQUIRE(VirtFs::isDirectory("testQ/") == false); + REQUIRE(VirtFs::isDirectory("testQ//") == false); + + VirtFs::unmountDirSilent2(prefix + "data", + "test"); + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("VirtFs1 isDirectory4") +{ + VirtFs::init("."); + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../" + prefix; + + VirtFs::mountZip2(prefix + "data/test/test2.zip", + "dir", + Append_false); + + REQUIRE(VirtFs::isDirectory("dir2/units.xml") == false); + REQUIRE(VirtFs::isDirectory("dir2/units.xml/") == false); + REQUIRE(VirtFs::isDirectory("dir2//units.xml") == false); + REQUIRE(VirtFs::isDirectory("dir2/units123.xml") == false); + REQUIRE(VirtFs::isDirectory("dir2//units123.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ//units.xml") == false); + REQUIRE(VirtFs::isDirectory("units.xml") == false); + REQUIRE(VirtFs::isDirectory("1") == true); + REQUIRE(VirtFs::isDirectory("gpl") == true); + REQUIRE(VirtFs::isDirectory("dir2/") == false); + REQUIRE(VirtFs::isDirectory("dir/1") == false); + REQUIRE(VirtFs::isDirectory("dir/1/zzz") == false); + REQUIRE(VirtFs::isDirectory("test/dir1\\") == false); + REQUIRE(VirtFs::isDirectory("testQ") == false); + REQUIRE(VirtFs::isDirectory("testQ/") == false); + REQUIRE(VirtFs::isDirectory("testQ//") == false); + + VirtFs::unmountZip2(prefix + "data/test/test2.zip", + "dir"); + VirtFs::deinit(); + delete2(logger); +} + TEST_CASE("VirtFs1 openRead1") { VirtFs::init("."); |