From 873eff85f179593d486793be24b3cfaf73226e1f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 May 2017 18:22:09 +0300 Subject: Add subdir support in VirtFs::getDirs. --- src/fs/virtfs/fsdir.cpp | 4 +-- src/fs/virtfs/fsdir.h | 2 +- src/fs/virtfs/fsfuncs.h | 2 +- src/fs/virtfs/fszip.cpp | 5 +++- src/fs/virtfs/fszip.h | 2 +- src/fs/virtfs/virtfs1_unittest.cc | 61 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp index 10e980722..966ab4025 100644 --- a/src/fs/virtfs/fsdir.cpp +++ b/src/fs/virtfs/fsdir.cpp @@ -619,10 +619,10 @@ namespace FsDir } void getDirs(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names) { - const std::string path = entry->root + dirName; + const std::string path = entry->root + entry->subDir + dirName; const struct dirent *next_file = nullptr; DIR *const dir = opendir(path.c_str()); if (dir) diff --git a/src/fs/virtfs/fsdir.h b/src/fs/virtfs/fsdir.h index 3c4f4a46d..0c19fee2f 100644 --- a/src/fs/virtfs/fsdir.h +++ b/src/fs/virtfs/fsdir.h @@ -65,7 +65,7 @@ namespace FsDir const std::string &dirName, StringVect &names); void getDirs(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names); bool isDirectory(FsEntry *restrict const entry, std::string dirName, diff --git a/src/fs/virtfs/fsfuncs.h b/src/fs/virtfs/fsfuncs.h index c0dc2a7c1..49d10e12f 100644 --- a/src/fs/virtfs/fsfuncs.h +++ b/src/fs/virtfs/fsfuncs.h @@ -98,7 +98,7 @@ struct FsFuncs final const std::string &dirName, StringVect &names); void (*getDirs) (FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names); bool (*isDirectory) (FsEntry *restrict const entry, std::string dirName, diff --git a/src/fs/virtfs/fszip.cpp b/src/fs/virtfs/fszip.cpp index b2e123f49..cc720f626 100644 --- a/src/fs/virtfs/fszip.cpp +++ b/src/fs/virtfs/fszip.cpp @@ -408,10 +408,13 @@ namespace FsZip } void getDirs(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names) { ZipEntry *const zipEntry = static_cast(entry); + const std::string subDir = zipEntry->subDir; + if (subDir != dirSeparator) + dirName = pathJoin(subDir, dirName); if (dirName == dirSeparator) { FOR_EACH (std::vector::const_iterator, diff --git a/src/fs/virtfs/fszip.h b/src/fs/virtfs/fszip.h index 76bb1e148..92cfd0ab6 100644 --- a/src/fs/virtfs/fszip.h +++ b/src/fs/virtfs/fszip.h @@ -52,7 +52,7 @@ namespace FsZip const std::string &dirName, StringVect &names); void getDirs(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names); bool isDirectory(FsEntry *restrict const entry, std::string dirName, diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc index 43834d87e..c703e3717 100644 --- a/src/fs/virtfs/virtfs1_unittest.cc +++ b/src/fs/virtfs/virtfs1_unittest.cc @@ -3240,6 +3240,67 @@ TEST_CASE("VirtFs1 getDirs2") delete2(logger); } +TEST_CASE("VirtFs1 getDirs3") +{ + 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); + + StringVect list; + VirtFs::getDirs(dirSeparator, list); + REQUIRE(list.size() == 2); + REQUIRE(inList(list, "1")); + REQUIRE(inList(list, "gpl")); + list.clear(); + + VirtFs::getDirs("1", list); + REQUIRE(list.size() == 0); + + VirtFs::unmountZip2(prefix + "data/test/test2.zip", + "dir"); + VirtFs::deinit(); + delete2(logger); +} + +TEST_CASE("VirtFs1 getDirs4") +{ + VirtFs::init("."); + logger = new Logger(); + std::string name("data/test/test.zip"); + std::string prefix; + if (Files::existsLocal(name) == false) + prefix = "../" + prefix; + StringVect list; + + SECTION("dir1") + { + VirtFs::mountDir2(prefix + "data", + "test", + Append_false); + + VirtFs::getDirs("/", list); + REQUIRE(inList(list, "dir1")); + REQUIRE(inList(list, "dir2")); + list.clear(); + + VirtFs::getDirs("dir1", list); + REQUIRE(list.size() == 0); + + VirtFs::unmountDir2(prefix + "data", + "test"); + } + + VirtFs::deinit(); + delete2(logger); +} + TEST_CASE("VirtFs1 getFilesWithDir1") { VirtFs::init("."); -- cgit v1.2.3-70-g09d2