diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-05-16 18:10:29 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-05-16 18:10:29 +0300 |
commit | 5844f83998040d4a79dc442151a21dc17de60feb (patch) | |
tree | 676268ac999c9009eca96a182f3de9571da24d67 /src | |
parent | 3cf47056f239f1096590c27c1d401904a54f84fc (diff) | |
download | plus-5844f83998040d4a79dc442151a21dc17de60feb.tar.gz plus-5844f83998040d4a79dc442151a21dc17de60feb.tar.bz2 plus-5844f83998040d4a79dc442151a21dc17de60feb.tar.xz plus-5844f83998040d4a79dc442151a21dc17de60feb.zip |
Add subdir support in VirtFs::getFiles.
Diffstat (limited to 'src')
-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 | 7 | ||||
-rw-r--r-- | src/fs/virtfs/fszip.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/virtfs1_unittest.cc | 33 | ||||
-rw-r--r-- | src/fs/virtfs/virtfs_unittest.cc | 41 |
7 files changed, 82 insertions, 9 deletions
diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp index bafe3d2e3..10e980722 100644 --- a/src/fs/virtfs/fsdir.cpp +++ b/src/fs/virtfs/fsdir.cpp @@ -521,10 +521,10 @@ namespace FsDir } void getFiles(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 ada58943e..3c4f4a46d 100644 --- a/src/fs/virtfs/fsdir.h +++ b/src/fs/virtfs/fsdir.h @@ -59,7 +59,7 @@ namespace FsDir std::string dirName, StringVect &names); void getFiles(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names); void getFilesWithDir(FsEntry *restrict const entry, const std::string &dirName, diff --git a/src/fs/virtfs/fsfuncs.h b/src/fs/virtfs/fsfuncs.h index 989ee558e..c0dc2a7c1 100644 --- a/src/fs/virtfs/fsfuncs.h +++ b/src/fs/virtfs/fsfuncs.h @@ -92,7 +92,7 @@ struct FsFuncs final std::string dirName, StringVect &names); void (*getFiles) (FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names); void (*getFilesWithDir) (FsEntry *restrict const entry, const std::string &dirName, diff --git a/src/fs/virtfs/fszip.cpp b/src/fs/virtfs/fszip.cpp index 91d323cc1..b2e123f49 100644 --- a/src/fs/virtfs/fszip.cpp +++ b/src/fs/virtfs/fszip.cpp @@ -156,7 +156,7 @@ namespace FsZip StringVect &names) { ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry); - std::string subDir = zipEntry->subDir; + const std::string subDir = zipEntry->subDir; if (subDir != dirSeparator) dirName = pathJoin(subDir, dirName); if (dirName == dirSeparator) @@ -215,10 +215,13 @@ namespace FsZip } void getFiles(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names) { ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry); + const std::string subDir = zipEntry->subDir; + if (subDir != dirSeparator) + dirName = pathJoin(subDir, dirName); if (dirName == dirSeparator) { FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator, diff --git a/src/fs/virtfs/fszip.h b/src/fs/virtfs/fszip.h index 68466a25c..76bb1e148 100644 --- a/src/fs/virtfs/fszip.h +++ b/src/fs/virtfs/fszip.h @@ -46,7 +46,7 @@ namespace FsZip std::string dirName, StringVect &names); void getFiles(FsEntry *restrict const entry, - const std::string &dirName, + std::string dirName, StringVect &names); void getFilesWithDir(FsEntry *restrict const entry, const std::string &dirName, diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc index 4c046b621..43834d87e 100644 --- a/src/fs/virtfs/virtfs1_unittest.cc +++ b/src/fs/virtfs/virtfs1_unittest.cc @@ -3103,7 +3103,7 @@ TEST_CASE("VirtFs1 rwops_read3") delete2(logger); } -TEST_CASE("VirtFs1 getFiles zip") +TEST_CASE("VirtFs1 getFiles zip1") { VirtFs::init("."); logger = new Logger(); @@ -3134,6 +3134,37 @@ TEST_CASE("VirtFs1 getFiles zip") delete2(logger); } +TEST_CASE("VirtFs1 getFiles zip2") +{ + 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::getFiles(dirSeparator, list); + REQUIRE(list.size() == 2); + REQUIRE(inList(list, "dye.png")); + REQUIRE(inList(list, "hide.png")); + + list.clear(); + VirtFs::getFiles("1", list); + REQUIRE(list.size() == 2); + REQUIRE(inList(list, "file1.txt")); + REQUIRE(inList(list, "test.txt")); + + VirtFs::unmountZip2(prefix + "data/test/test2.zip", + "dir"); + VirtFs::deinit(); + delete2(logger); +} + TEST_CASE("VirtFs1 getDirs1") { VirtFs::init("."); diff --git a/src/fs/virtfs/virtfs_unittest.cc b/src/fs/virtfs/virtfs_unittest.cc index d6ab42ff4..24b9232fc 100644 --- a/src/fs/virtfs/virtfs_unittest.cc +++ b/src/fs/virtfs/virtfs_unittest.cc @@ -778,7 +778,7 @@ TEST_CASE("VirtFs getrealDir3") delete2(logger); } -TEST_CASE("VirtFs permitLinks") +TEST_CASE("VirtFs permitLinks1") { logger = new Logger(); VirtFs::mountDirSilent("data", Append_false); @@ -811,6 +811,45 @@ TEST_CASE("VirtFs permitLinks") delete2(logger); } +TEST_CASE("VirtFs permitLinks2") +{ + logger = new Logger(); + VirtFs::mountDirSilent2("data", + "test", + Append_false); + VirtFs::mountDirSilent2("../data", + "test", + Append_false); + + const int cnt1 = VirtFs::exists("test2.txt") ? 26 : 25; + const int cnt2 = 26; + + StringVect list; + VirtFs::permitLinks(false); + VirtFs::getFiles(dirSeparator, list); + removeTemp(list); + const size_t sz = list.size(); + REQUIRE(sz == cnt1); + + list.clear(); + VirtFs::permitLinks(true); + VirtFs::getFiles(dirSeparator, list); + removeTemp(list); + REQUIRE(list.size() == cnt2); + + list.clear(); + VirtFs::permitLinks(false); + VirtFs::getFiles(dirSeparator, list); + removeTemp(list); + REQUIRE(list.size() == cnt1); + + VirtFs::unmountDirSilent2("data", + "test"); + VirtFs::unmountDirSilent2("../data", + "test"); + delete2(logger); +} + TEST_CASE("VirtFs read1") { logger = new Logger(); |