summaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-16 18:22:09 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-16 18:22:09 +0300
commit873eff85f179593d486793be24b3cfaf73226e1f (patch)
tree23cfa3747f31a853f13c251b247312ddbcd70b53 /src/fs
parent5844f83998040d4a79dc442151a21dc17de60feb (diff)
downloadmanaverse-873eff85f179593d486793be24b3cfaf73226e1f.tar.gz
manaverse-873eff85f179593d486793be24b3cfaf73226e1f.tar.bz2
manaverse-873eff85f179593d486793be24b3cfaf73226e1f.tar.xz
manaverse-873eff85f179593d486793be24b3cfaf73226e1f.zip
Add subdir support in VirtFs::getDirs.
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/virtfs/fsdir.cpp4
-rw-r--r--src/fs/virtfs/fsdir.h2
-rw-r--r--src/fs/virtfs/fsfuncs.h2
-rw-r--r--src/fs/virtfs/fszip.cpp5
-rw-r--r--src/fs/virtfs/fszip.h2
-rw-r--r--src/fs/virtfs/virtfs1_unittest.cc61
6 files changed, 70 insertions, 6 deletions
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<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 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(".");