summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/fs.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-16 22:41:56 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-16 22:41:56 +0300
commit8e0bd85107f57e900658129f9cfbded0866f0883 (patch)
tree05dab2c86bcf6d079c69ecb40dea258a6572fbbe /src/fs/virtfs/fs.cpp
parentba71181d5e6fd35083a9e7a86c8e1a9592581398 (diff)
downloadplus-8e0bd85107f57e900658129f9cfbded0866f0883.tar.gz
plus-8e0bd85107f57e900658129f9cfbded0866f0883.tar.bz2
plus-8e0bd85107f57e900658129f9cfbded0866f0883.tar.xz
plus-8e0bd85107f57e900658129f9cfbded0866f0883.zip
Improve a bit subDir empty check in virtfs.
Diffstat (limited to 'src/fs/virtfs/fs.cpp')
-rw-r--r--src/fs/virtfs/fs.cpp50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/fs/virtfs/fs.cpp b/src/fs/virtfs/fs.cpp
index d8f815562..02f1910be 100644
--- a/src/fs/virtfs/fs.cpp
+++ b/src/fs/virtfs/fs.cpp
@@ -351,8 +351,15 @@ namespace VirtFs
std::string rootDir = newDir;
if (findLast(rootDir, std::string(dirSeparator)) == false)
rootDir += dirSeparator;
- if (findLast(subDir, std::string(dirSeparator)) == false)
+ if (subDir == dirSeparator)
+ {
+ subDir.clear();
+ }
+ else if (!subDir.empty() &&
+ findLast(subDir, std::string(dirSeparator)) == false)
+ {
subDir += dirSeparator;
+ }
const FsEntry *const entry = searchByRootInternal(rootDir, subDir);
if (entry != nullptr)
{
@@ -404,7 +411,7 @@ namespace VirtFs
newDir.c_str());
return false;
}
- return mountDirInternal(newDir, dirSeparator, append);
+ return mountDirInternal(newDir, std::string(), append);
}
bool mountDirSilent2(std::string newDir,
@@ -432,7 +439,7 @@ namespace VirtFs
logger->log("VirtFs::mount directory not exists: %s",
newDir.c_str());
}
- return mountDirInternal(newDir, dirSeparator,append);
+ return mountDirInternal(newDir, std::string() ,append);
}
bool mountDirSilentTest2(std::string newDir,
@@ -455,8 +462,15 @@ namespace VirtFs
{
if (findLast(oldDir, std::string(dirSeparator)) == false)
oldDir += dirSeparator;
- if (findLast(subDir, std::string(dirSeparator)) == false)
+ if (subDir == dirSeparator)
+ {
+ subDir.clear();
+ }
+ else if (!subDir.empty() &&
+ findLast(subDir, std::string(dirSeparator)) == false)
+ {
subDir += dirSeparator;
+ }
FOR_EACH (std::vector<FsEntry*>::iterator, it, mEntries)
{
FsEntry *const entry = *it;
@@ -483,7 +497,7 @@ namespace VirtFs
reportAlways("Called unmount with zip archive");
return false;
}
- if (unmountDirInternal(oldDir, dirSeparator) == false)
+ if (unmountDirInternal(oldDir, std::string()) == false)
{
reportAlways("VirtFs::unmountDir not exists: %s",
oldDir.c_str());
@@ -519,7 +533,7 @@ namespace VirtFs
reportAlways("Called unmount with zip archive");
return false;
}
- if (unmountDirInternal(oldDir, dirSeparator) == false)
+ if (unmountDirInternal(oldDir, std::string()) == false)
{
logger->log("VirtFs::unmountDir not exists: %s",
oldDir.c_str());
@@ -563,14 +577,14 @@ namespace VirtFs
"zip archive");
return false;
}
- if (searchByRootInternal(newDir, dirSeparator) != nullptr)
+ if (searchByRootInternal(newDir, std::string()) != nullptr)
{
reportAlways("FsZip::mount already exists: %s",
newDir.c_str());
return false;
}
ZipEntry *const entry = new ZipEntry(newDir,
- dirSeparator,
+ std::string(),
FsZip::getFuncs());
if (ZipReader::readArchiveInfo(entry) == false)
{
@@ -601,8 +615,15 @@ namespace VirtFs
return false;
}
prepareFsPath(subDir);
- if (findLast(subDir, std::string(dirSeparator)) == false)
+ if (subDir == dirSeparator)
+ {
+ subDir.clear();
+ }
+ else if (!subDir.empty() &&
+ findLast(subDir, std::string(dirSeparator)) == false)
+ {
subDir += dirSeparator;
+ }
if (searchByRootInternal(newDir, subDir) != nullptr)
{
reportAlways("FsZip::mount already exists: %s",
@@ -636,7 +657,7 @@ namespace VirtFs
FsEntry *const entry = *it;
if (entry->root == oldDir &&
entry->type == FsEntryType::Zip &&
- entry->subDir == dirSeparator)
+ entry->subDir == std::string())
{
ZipEntry *const zipEntry = static_cast<ZipEntry*>(
entry);
@@ -662,8 +683,15 @@ namespace VirtFs
return false;
}
prepareFsPath(subDir);
- if (findLast(subDir, std::string(dirSeparator)) == false)
+ if (subDir == dirSeparator)
+ {
+ subDir.clear();
+ }
+ else if (!subDir.empty() &&
+ findLast(subDir, std::string(dirSeparator)) == false)
+ {
subDir += dirSeparator;
+ }
FOR_EACH (std::vector<FsEntry*>::iterator, it, mEntries)
{
FsEntry *const entry = *it;