summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-16 17:32:31 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-16 17:32:31 +0300
commit5f66478632d388bfae78cbbb938a42eac3956db2 (patch)
tree106a737e821a8d3c79bf0ae172c66c18305cf990 /src
parent0a849f982988cbd7c7afdedccb210bada702238b (diff)
downloadplus-5f66478632d388bfae78cbbb938a42eac3956db2.tar.gz
plus-5f66478632d388bfae78cbbb938a42eac3956db2.tar.bz2
plus-5f66478632d388bfae78cbbb938a42eac3956db2.tar.xz
plus-5f66478632d388bfae78cbbb938a42eac3956db2.zip
Add subdir support in VirtFs::openRead.
Diffstat (limited to 'src')
-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.cc159
6 files changed, 168 insertions, 6 deletions
diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp
index 5d6f97d8e..2e69dedb1 100644
--- a/src/fs/virtfs/fsdir.cpp
+++ b/src/fs/virtfs/fsdir.cpp
@@ -65,7 +65,7 @@ namespace FsDir
const std::string &filename,
const FILEMTYPE mode)
{
- const std::string path = entry->root + filename;
+ const std::string path = entry->root + entry->subDir + filename;
if (Files::existsLocal(path) == false)
return nullptr;
FILEHTYPE fd = FILEOPEN(path.c_str(),
@@ -81,7 +81,7 @@ namespace FsDir
}
File *openRead(FsEntry *restrict const entry,
- const std::string &filename)
+ std::string filename)
{
return openInternal(entry, filename, FILEOPEN_FLAG_READ);
}
diff --git a/src/fs/virtfs/fsdir.h b/src/fs/virtfs/fsdir.h
index d797a78ea..704d7e916 100644
--- a/src/fs/virtfs/fsdir.h
+++ b/src/fs/virtfs/fsdir.h
@@ -41,7 +41,7 @@ namespace FsDir
const std::string &filename,
const FILEMTYPE mode);
File *openRead(FsEntry *restrict const entry,
- const std::string &filename);
+ std::string filename);
File *openWrite(FsEntry *restrict const entry,
const std::string &filename);
File *openAppend(FsEntry *restrict const entry,
diff --git a/src/fs/virtfs/fsfuncs.h b/src/fs/virtfs/fsfuncs.h
index 4f409cc72..6c5428b49 100644
--- a/src/fs/virtfs/fsfuncs.h
+++ b/src/fs/virtfs/fsfuncs.h
@@ -104,7 +104,7 @@ struct FsFuncs final
std::string dirName,
bool &isDirFlag);
File *(*openRead) (FsEntry *restrict const entry,
- const std::string &filename);
+ std::string filename);
File *(*openWrite) (FsEntry *restrict const entry,
const std::string &filename);
File *(*openAppend) (FsEntry *restrict const entry,
diff --git a/src/fs/virtfs/fszip.cpp b/src/fs/virtfs/fszip.cpp
index e7fab595f..f2f16bcbb 100644
--- a/src/fs/virtfs/fszip.cpp
+++ b/src/fs/virtfs/fszip.cpp
@@ -526,9 +526,12 @@ namespace FsZip
}
File *openRead(FsEntry *restrict const entry,
- const std::string &filename)
+ std::string filename)
{
ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
+ std::string subDir = zipEntry->subDir;
+ if (subDir != dirSeparator)
+ filename = pathJoin(subDir, filename);
FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
it2,
zipEntry->mHeaders)
diff --git a/src/fs/virtfs/fszip.h b/src/fs/virtfs/fszip.h
index cd847b3b0..fbd6dba4d 100644
--- a/src/fs/virtfs/fszip.h
+++ b/src/fs/virtfs/fszip.h
@@ -59,7 +59,7 @@ namespace FsZip
bool &isDirFlag);
void freeList(List *restrict const handle);
File *openRead(FsEntry *restrict const entry,
- const std::string &filename);
+ std::string filename);
File *openWrite(FsEntry *restrict const entry,
const std::string &filename);
File *openAppend(FsEntry *restrict const entry,
diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc
index ae3c00118..78787f9d0 100644
--- a/src/fs/virtfs/virtfs1_unittest.cc
+++ b/src/fs/virtfs/virtfs1_unittest.cc
@@ -2216,6 +2216,165 @@ TEST_CASE("VirtFs1 openRead2")
delete2(logger);
}
+TEST_CASE("VirtFs1 openRead3")
+{
+ 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);
+
+ VirtFs::File *file = nullptr;
+
+ file = VirtFs::openRead("units.xml");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("test/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("units123.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("tesQ/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("testQ");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("file1.txt");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("file2.txt");
+ REQUIRE(file == nullptr);
+
+ VirtFs::mountDir2(prefix + "data/test",
+ "dir2",
+ Append_false);
+
+ file = VirtFs::openRead("units.xml");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("test/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("units123.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("tesQ/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("testQ");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("file1.txt");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("file2.txt");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+
+ VirtFs::unmountDir2(prefix + "data/test",
+ "dir2");
+
+ file = VirtFs::openRead("units.xml");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("test/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("units123.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("tesQ/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("testQ");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("file1.txt");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("file2.txt");
+ REQUIRE(file == nullptr);
+
+ VirtFs::unmountDir2(prefix + "data",
+ "test");
+ VirtFs::deinit();
+ delete2(logger);
+}
+
+TEST_CASE("VirtFs1 openRead4")
+{
+ VirtFs::init(".");
+ logger = new Logger();
+ std::string name("data/test/test.zip");
+ std::string prefix("data/test/");
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+
+ VirtFs::mountZip2(prefix + "test2.zip",
+ "dir",
+ Append_false);
+
+ VirtFs::File *file = nullptr;
+
+ file = VirtFs::openRead("dye.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("1\\test.txt");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("dir/dye.png");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("tesQ/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("dye.png1");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("testQ");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("brimmedhat.png");
+ REQUIRE(file == nullptr);
+
+ VirtFs::mountZip2(prefix + "test.zip",
+ "dir",
+ Append_false);
+
+ file = VirtFs::openRead("dye.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("1\\test.txt");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("dir/dye.png");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("tesQ/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("dye.png1");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("testQ");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("brimmedhat.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+
+ VirtFs::unmountZip2(prefix + "test.zip",
+ "dir");
+
+ file = VirtFs::openRead("dye.png");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("1\\test.txt");
+ REQUIRE(file != nullptr);
+ VirtFs::close(file);
+ file = VirtFs::openRead("dir/dye.png");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("tesQ/units.xml");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("dye.png1");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("testQ");
+ REQUIRE(file == nullptr);
+ file = VirtFs::openRead("brimmedhat.png");
+ REQUIRE(file == nullptr);
+
+ VirtFs::unmountZip2(prefix + "test2.zip",
+ "dir");
+
+ VirtFs::deinit();
+ delete2(logger);
+}
+
TEST_CASE("VirtFs1 permitLinks")
{
VirtFs::init(".");