summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-16 01:01:55 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-16 01:46:05 +0300
commit24bd6a6d26bab89126db7183bb693779a1742c6d (patch)
tree1a7ae594883562a01abdb2c8070a6585af2780e4
parent65ef43ab06f3dfb7b87caa3ba8236ea741d59f35 (diff)
downloadmv-24bd6a6d26bab89126db7183bb693779a1742c6d.tar.gz
mv-24bd6a6d26bab89126db7183bb693779a1742c6d.tar.bz2
mv-24bd6a6d26bab89126db7183bb693779a1742c6d.tar.xz
mv-24bd6a6d26bab89126db7183bb693779a1742c6d.zip
Add subdir support into virtfs::exists.
-rw-r--r--src/fs/virtfs/fs.cpp12
-rw-r--r--src/fs/virtfs/fs.h4
-rw-r--r--src/fs/virtfs/fsdir.cpp6
-rw-r--r--src/fs/virtfs/fsdir.h4
-rw-r--r--src/fs/virtfs/fsfuncs.h4
-rw-r--r--src/fs/virtfs/fszip.cpp12
-rw-r--r--src/fs/virtfs/fszip.h4
-rw-r--r--src/fs/virtfs/virtfs1_unittest.cc249
-rw-r--r--src/fs/virtfs/virtfs_unittest.cc31
9 files changed, 223 insertions, 103 deletions
diff --git a/src/fs/virtfs/fs.cpp b/src/fs/virtfs/fs.cpp
index 61251bb35..d8f815562 100644
--- a/src/fs/virtfs/fs.cpp
+++ b/src/fs/virtfs/fs.cpp
@@ -340,7 +340,7 @@ namespace VirtFs
}
bool mountDirInternal(const std::string &restrict newDir,
- const std::string &restrict subDir,
+ std::string subDir,
const Append append)
{
if (newDir.find(".zip") != std::string::npos)
@@ -351,6 +351,8 @@ namespace VirtFs
std::string rootDir = newDir;
if (findLast(rootDir, std::string(dirSeparator)) == false)
rootDir += dirSeparator;
+ if (findLast(subDir, std::string(dirSeparator)) == false)
+ subDir += dirSeparator;
const FsEntry *const entry = searchByRootInternal(rootDir, subDir);
if (entry != nullptr)
{
@@ -449,10 +451,12 @@ namespace VirtFs
#endif // UNITTESTS
bool unmountDirInternal(std::string oldDir,
- const std::string &restrict subDir)
+ std::string subDir)
{
if (findLast(oldDir, std::string(dirSeparator)) == false)
oldDir += dirSeparator;
+ if (findLast(subDir, std::string(dirSeparator)) == false)
+ subDir += dirSeparator;
FOR_EACH (std::vector<FsEntry*>::iterator, it, mEntries)
{
FsEntry *const entry = *it;
@@ -597,6 +601,8 @@ namespace VirtFs
return false;
}
prepareFsPath(subDir);
+ if (findLast(subDir, std::string(dirSeparator)) == false)
+ subDir += dirSeparator;
if (searchByRootInternal(newDir, subDir) != nullptr)
{
reportAlways("FsZip::mount already exists: %s",
@@ -656,6 +662,8 @@ namespace VirtFs
return false;
}
prepareFsPath(subDir);
+ if (findLast(subDir, std::string(dirSeparator)) == false)
+ subDir += dirSeparator;
FOR_EACH (std::vector<FsEntry*>::iterator, it, mEntries)
{
FsEntry *const entry = *it;
diff --git a/src/fs/virtfs/fs.h b/src/fs/virtfs/fs.h
index ccd5dcfdc..ca67117ea 100644
--- a/src/fs/virtfs/fs.h
+++ b/src/fs/virtfs/fs.h
@@ -94,10 +94,10 @@ namespace VirtFs
int eof(File *restrict const file);
bool mountDirInternal(const std::string &restrict newDir,
- const std::string &restrict subDir,
+ std::string subDir,
const Append append);
bool unmountDirInternal(std::string oldDir,
- const std::string &restrict subDir);
+ std::string subDir);
std::vector<FsEntry*> &getEntries();
FsEntry *searchByRootInternal(const std::string &restrict root,
const std::string &restrict subDir);
diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp
index 4ee6d648e..f7642c72c 100644
--- a/src/fs/virtfs/fsdir.cpp
+++ b/src/fs/virtfs/fsdir.cpp
@@ -182,10 +182,10 @@ namespace FsDir
}
bool exists(FsEntry *restrict const entry,
- const std::string &fileName,
- const std::string &dirName A_UNUSED)
+ std::string fileName,
+ std::string dirName A_UNUSED)
{
- return Files::existsLocal(entry->root + fileName);
+ return Files::existsLocal(entry->root + entry->subDir + fileName);
}
void enumerate(FsEntry *restrict const entry,
diff --git a/src/fs/virtfs/fsdir.h b/src/fs/virtfs/fsdir.h
index e57036043..bba9eaf59 100644
--- a/src/fs/virtfs/fsdir.h
+++ b/src/fs/virtfs/fsdir.h
@@ -53,8 +53,8 @@ namespace FsDir
void initFuncs(FsFuncs *restrict const ptr);
void deinit();
bool exists(FsEntry *restrict const entry,
- const std::string &fileName,
- const std::string &dirName);
+ std::string fileName,
+ std::string dirName);
void enumerate(FsEntry *restrict const entry,
const std::string &dirName,
StringVect &names);
diff --git a/src/fs/virtfs/fsfuncs.h b/src/fs/virtfs/fsfuncs.h
index e9a79562c..eabf799b0 100644
--- a/src/fs/virtfs/fsfuncs.h
+++ b/src/fs/virtfs/fsfuncs.h
@@ -82,8 +82,8 @@ struct FsFuncs final
int (*seek) (File *restrict const file,
const uint64_t pos);
bool (*exists) (FsEntry *restrict const entry,
- const std::string &filename,
- const std::string &dirName);
+ std::string filename,
+ std::string dirName);
bool (*getRealDir) (FsEntry *restrict const entry,
const std::string &filename,
const std::string &dirName,
diff --git a/src/fs/virtfs/fszip.cpp b/src/fs/virtfs/fszip.cpp
index eda5dd078..562e0bc80 100644
--- a/src/fs/virtfs/fszip.cpp
+++ b/src/fs/virtfs/fszip.cpp
@@ -118,10 +118,18 @@ namespace FsZip
}
bool exists(FsEntry *restrict const entry,
- const std::string &filename,
- const std::string &dirName)
+ std::string filename,
+ std::string dirName)
{
ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
+ std::string subDir = zipEntry->subDir;
+ if (subDir != dirSeparator)
+ {
+ filename = pathJoin(subDir, filename);
+ dirName = pathJoin(subDir, dirName);
+ }
+ if (subDir == dirSeparator)
+ subDir.clear();
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 4caffba17..7935702cc 100644
--- a/src/fs/virtfs/fszip.h
+++ b/src/fs/virtfs/fszip.h
@@ -40,8 +40,8 @@ namespace FsZip
void initFuncs(FsFuncs *restrict const ptr);
void deinit();
bool exists(FsEntry *restrict const entry,
- const std::string &filename,
- const std::string &dirName);
+ std::string filename,
+ std::string dirName);
void enumerate(FsEntry *restrict const entry,
const std::string &dirName,
StringVect &names);
diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc
index f4dc740dd..d34af34aa 100644
--- a/src/fs/virtfs/virtfs1_unittest.cc
+++ b/src/fs/virtfs/virtfs1_unittest.cc
@@ -233,15 +233,15 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir1",
"dir2",
Append_false));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2") ==
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -252,15 +252,15 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir1/",
"dir2",
Append_true));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2") ==
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1" + sep);
@@ -274,21 +274,21 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir2",
"dir4",
Append_false));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3") ==
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4");
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir3");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir3" + sep);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir2");
REQUIRE(static_cast<VirtFs::DirEntry*>(
@@ -303,21 +303,21 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir2",
"dir4",
Append_true));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1") ==
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir1" + sep) ==
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3") ==
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[1]->root == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3");
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1" + sep);
REQUIRE(static_cast<VirtFs::DirEntry*>(
@@ -335,13 +335,13 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir3/test",
"dir5",
Append_true));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir3" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir2" + sep, "dir4" + sep) !=
nullptr);
REQUIRE(VirtFs::searchByRootInternal(
- "dir3" + sep + "test" + sep, "dir5") != nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3") ==
+ "dir3" + sep + "test" + sep, "dir5" + sep) != nullptr);
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir3" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
@@ -350,9 +350,9 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3");
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4");
- REQUIRE(VirtFs::getEntries()[2]->subDir == "dir5");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir4" + sep);
+ REQUIRE(VirtFs::getEntries()[2]->subDir == "dir5" + sep);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
REQUIRE(static_cast<VirtFs::DirEntry*>(
@@ -373,13 +373,14 @@ TEST_CASE("VirtFs1 mountDir")
"dir3\\test",
Append_false));
REQUIRE(VirtFs::searchByRootInternal(
- "dir1" + sep + "", "dir1") != nullptr);
+ "dir1" + sep + "", "dir1" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
- "dir2" + sep + "", "dir2") != nullptr);
+ "dir2" + sep + "", "dir2" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
- "dir3" + sep + "test" + sep, "dir3" + sep + "test") != nullptr);
+ "dir3" + sep + "test" + sep,
+ "dir3" + sep + "test" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
- "test" + sep + "", "dir1") == nullptr);
+ "test" + sep + "", "dir1" + sep) == nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep + "test" + sep);
REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
@@ -387,9 +388,10 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Dir);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep + "test");
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1");
- REQUIRE(VirtFs::getEntries()[2]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir ==
+ "dir3" + sep + "test" + sep);
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep);
+ REQUIRE(VirtFs::getEntries()[2]->subDir == "dir2" + sep);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3" + sep + "test");
REQUIRE(static_cast<VirtFs::DirEntry*>(
@@ -405,18 +407,18 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir1",
"dir2",
Append_true));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, dirSeparator) !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2") ==
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->subDir == sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -426,7 +428,7 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::unmountDirSilent("dir1"));
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -439,18 +441,18 @@ TEST_CASE("VirtFs1 mountDir")
REQUIRE(VirtFs::mountDirSilentTest2("dir1",
"dir2",
Append_true));
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, dirSeparator) !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2") !=
+ REQUIRE(VirtFs::searchByRootInternal("dir1" + sep, "dir2" + sep) !=
nullptr);
- REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2") ==
+ REQUIRE(VirtFs::searchByRootInternal("test" + sep, "dir2" + sep) ==
nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->subDir == sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[1]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -613,7 +615,7 @@ TEST_CASE("VirtFs1 mountZip")
"dir1",
Append_false));
REQUIRE(VirtFs::searchByRootInternal(
- prefix + "data" + sep + "test" + sep + "test.zip", "dir1") !=
+ prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) !=
nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip", dirSeparator) ==
@@ -621,7 +623,7 @@ TEST_CASE("VirtFs1 mountZip")
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
}
@@ -634,20 +636,20 @@ TEST_CASE("VirtFs1 mountZip")
"dir2",
Append_false));
REQUIRE(VirtFs::searchByRootInternal(
- prefix + "data" + sep + "test" + sep + "test.zip", "dir1") !=
+ prefix + "data" + sep + "test" + sep + "test.zip", "dir1" + sep) !=
nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep);
}
SECTION("subDir 3")
@@ -660,19 +662,19 @@ TEST_CASE("VirtFs1 mountZip")
Append_true));
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test.zip",
- "dir1") != nullptr);
+ "dir1" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
}
SECTION("subDir 4")
@@ -688,26 +690,26 @@ TEST_CASE("VirtFs1 mountZip")
Append_false));
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test.zip",
- "dir1") != nullptr);
+ "dir1" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir3") != nullptr);
+ "dir3" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep + "");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[2]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1" + sep);
}
SECTION("subDir 5")
@@ -723,26 +725,26 @@ TEST_CASE("VirtFs1 mountZip")
Append_true));
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test.zip",
- "dir1") != nullptr);
+ "dir1" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir3") != nullptr);
+ "dir3" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "");
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[2]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
- REQUIRE(VirtFs::getEntries()[2]->subDir == "dir3");
+ REQUIRE(VirtFs::getEntries()[2]->subDir == "dir3" + sep);
}
VirtFs::deinit();
@@ -962,7 +964,7 @@ TEST_CASE("VirtFs1 unmount")
REQUIRE(VirtFs::unmountDir2("dir1", "dir2"));
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3");
@@ -974,7 +976,7 @@ TEST_CASE("VirtFs1 unmount")
REQUIRE_THROWS(VirtFs::unmountDir("dir1"));
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3");
@@ -987,7 +989,7 @@ TEST_CASE("VirtFs1 unmount")
REQUIRE_THROWS(VirtFs::unmountDir("dir2/dir3" + sep));
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root == "dir3" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir4" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir3");
@@ -1000,7 +1002,7 @@ TEST_CASE("VirtFs1 unmount")
Append_true));
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -1013,7 +1015,7 @@ TEST_CASE("VirtFs1 unmount")
Append_true));
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root == "dir1" + sep);
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Dir);
REQUIRE(static_cast<VirtFs::DirEntry*>(
VirtFs::getEntries()[0])->userDir == "dir1");
@@ -1030,18 +1032,18 @@ TEST_CASE("VirtFs1 unmount")
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test.zip",
- "dir1") != nullptr);
+ "dir1" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Zip);
VirtFs::unmountZip2(prefix + "data/test/test.zip",
@@ -1051,11 +1053,11 @@ TEST_CASE("VirtFs1 unmount")
dirSeparator) == nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 1);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
}
@@ -1073,46 +1075,46 @@ TEST_CASE("VirtFs1 unmount")
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test.zip",
- "dir1") != nullptr);
+ "dir1" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir3") != nullptr);
+ "dir3" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 3);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
REQUIRE(VirtFs::getEntries()[2]->root ==
prefix + "data" + sep + "test" + sep + "test.zip");
- REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1");
+ REQUIRE(VirtFs::getEntries()[2]->subDir == "dir1" + sep);
REQUIRE(VirtFs::getEntries()[2]->type == FsEntryType::Zip);
VirtFs::unmountZip2(prefix + "data/test/test.zip",
"dir1");
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test.zip",
- "dir1") == nullptr);
+ "dir1" + sep) == nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "test2.zip",
- "dir3") != nullptr);
+ "dir3" + sep) != nullptr);
REQUIRE(VirtFs::searchByRootInternal(
prefix + "data" + sep + "test" + sep + "",
- "dir2") != nullptr);
+ "dir2" + sep) != nullptr);
REQUIRE(VirtFs::getEntries().size() == 2);
REQUIRE(VirtFs::getEntries()[0]->root ==
prefix + "data" + sep + "test" + sep + "test2.zip");
- REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3");
+ REQUIRE(VirtFs::getEntries()[0]->subDir == "dir3" + sep);
REQUIRE(VirtFs::getEntries()[0]->type == FsEntryType::Zip);
REQUIRE(VirtFs::getEntries()[1]->root ==
prefix + "data" + sep + "test" + sep);
- REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2");
+ REQUIRE(VirtFs::getEntries()[1]->subDir == "dir2" + sep);
REQUIRE(VirtFs::getEntries()[1]->type == FsEntryType::Dir);
}
@@ -1120,7 +1122,7 @@ TEST_CASE("VirtFs1 unmount")
delete2(logger);
}
-TEST_CASE("VirtFs1 exists")
+TEST_CASE("VirtFs1 exists1")
{
VirtFs::init(".");
logger = new Logger();
@@ -1180,6 +1182,77 @@ TEST_CASE("VirtFs1 exists")
delete2(logger);
}
+TEST_CASE("VirtFs1 exists2")
+{
+ VirtFs::init(".");
+ logger = new Logger();
+ const bool dir1 = VirtFs::mountDirSilent2("data/",
+ "test",
+ Append_false);
+ VirtFs::mountDirSilent2("..\\data",
+ "test",
+ Append_false);
+
+ REQUIRE(VirtFs::exists("test") == false);
+ REQUIRE(VirtFs::exists("test/") == false);
+ REQUIRE(VirtFs::exists("dir1"));
+ REQUIRE(VirtFs::exists("dir1/"));
+ REQUIRE(VirtFs::exists("dir") == false);
+ REQUIRE(VirtFs::exists("units.xml") == true);
+ REQUIRE(VirtFs::exists("units123.xml") == false);
+ REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
+ REQUIRE(VirtFs::exists("units.xml"));
+ REQUIRE(VirtFs::exists("file1.txt") == false);
+ REQUIRE(VirtFs::exists("file2.txt") == false);
+
+ if (dir1 == true)
+ {
+ VirtFs::mountDir2("data//test",
+ "dir2",
+ Append_false);
+ }
+ else
+ {
+ VirtFs::mountDirSilent2("..//data\\test",
+ "dir2",
+ Append_false);
+ }
+
+ REQUIRE(VirtFs::exists("test") == false);
+ REQUIRE(VirtFs::exists("test/") == false);
+ REQUIRE(VirtFs::exists("dir1"));
+ REQUIRE(VirtFs::exists("dir1/"));
+ REQUIRE(VirtFs::exists("dir") == false);
+ REQUIRE(VirtFs::exists("units.xml") == true);
+ REQUIRE(VirtFs::exists("units123.xml") == false);
+ REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
+ REQUIRE(VirtFs::exists("units.xml"));
+ REQUIRE(VirtFs::exists("file1.txt"));
+ REQUIRE(VirtFs::exists("file2.txt"));
+
+ if (dir1 == true)
+ VirtFs::unmountDirSilent2("data/test", "dir2");
+ else
+ VirtFs::unmountDirSilent2("../data/test", "dir2");
+
+ REQUIRE(VirtFs::exists("test") == false);
+ REQUIRE(VirtFs::exists("test/") == false);
+ REQUIRE(VirtFs::exists("dir1"));
+ REQUIRE(VirtFs::exists("dir1/"));
+ REQUIRE(VirtFs::exists("dir") == false);
+ REQUIRE(VirtFs::exists("units.xml") == true);
+ REQUIRE(VirtFs::exists("units123.xml") == false);
+ REQUIRE(VirtFs::exists("tesQ/units.xml") == false);
+ REQUIRE(VirtFs::exists("units.xml"));
+ REQUIRE(VirtFs::exists("file1.txt") == false);
+ REQUIRE(VirtFs::exists("file2.txt") == false);
+
+ REQUIRE_THROWS(VirtFs::exists("test/../units.xml"));
+
+ VirtFs::deinit();
+ delete2(logger);
+}
+
static void removeTemp(StringVect &restrict list)
{
int cnt = 0;
diff --git a/src/fs/virtfs/virtfs_unittest.cc b/src/fs/virtfs/virtfs_unittest.cc
index 8c7688cb6..3718fddda 100644
--- a/src/fs/virtfs/virtfs_unittest.cc
+++ b/src/fs/virtfs/virtfs_unittest.cc
@@ -190,6 +190,37 @@ TEST_CASE("VirtFs exists5")
delete2(logger);
}
+TEST_CASE("VirtFs exists6")
+{
+ 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::exists("test") == false);
+ REQUIRE(VirtFs::exists("test/units.xml") == false);
+ REQUIRE(VirtFs::exists("test.txt") == false);
+ REQUIRE(VirtFs::exists("dir/hide.png") == false);
+ REQUIRE(VirtFs::exists("dir/gpl") == false);
+ REQUIRE(VirtFs::exists("dir/gpl/zzz") == false);
+ REQUIRE(VirtFs::exists("units.xml") == false);
+ REQUIRE(VirtFs::exists("units.xml.") == false);
+ REQUIRE(VirtFs::exists("units.xml2") == false);
+ REQUIRE(VirtFs::exists("hide.png"));
+ REQUIRE(VirtFs::exists("dye.png"));
+ REQUIRE(VirtFs::exists("gpl"));
+ REQUIRE(VirtFs::exists("gpl/zzz") == false);
+
+ VirtFs::unmountZip2(prefix + "data/test/test2.zip",
+ "dir");
+ delete2(logger);
+}
+
static void removeTemp(StringVect &restrict list)
{
int cnt = 0;