From f024212615f581d5d6df033d0d5e7d1c474fbcea Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Mon, 15 May 2017 20:40:58 +0300
Subject: Add subdir parameter into mountZip functions.

---
 src/fs/virtfs/fs.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/fs/virtfs/fs.h   |  5 ++++
 2 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/src/fs/virtfs/fs.cpp b/src/fs/virtfs/fs.cpp
index 73cc04c02..61251bb35 100644
--- a/src/fs/virtfs/fs.cpp
+++ b/src/fs/virtfs/fs.cpp
@@ -579,6 +579,44 @@ namespace VirtFs
         return true;
     }
 
+    bool mountZip2(std::string newDir,
+                   std::string subDir,
+                   const Append append)
+    {
+        prepareFsPath(newDir);
+        if (Files::existsLocal(newDir) == false)
+        {
+            reportNonTests("FsZip::mount file not exists: %s",
+                newDir.c_str());
+            return false;
+        }
+        if (findLast(newDir, ".zip") == false)
+        {
+            reportAlways("Called VirtFs::mount without "
+                "zip archive");
+            return false;
+        }
+        prepareFsPath(subDir);
+        if (searchByRootInternal(newDir, subDir) != nullptr)
+        {
+            reportAlways("FsZip::mount already exists: %s",
+                newDir.c_str());
+            return false;
+        }
+        ZipEntry *const entry = new ZipEntry(newDir,
+            subDir,
+            FsZip::getFuncs());
+        if (ZipReader::readArchiveInfo(entry) == false)
+        {
+            delete entry;
+            return false;
+        }
+
+        logger->log("Add virtual zip: " + newDir);
+        addEntry(entry, append);
+        return true;
+    }
+
     bool unmountZip(std::string oldDir)
     {
         prepareFsPath(oldDir);
@@ -591,7 +629,39 @@ namespace VirtFs
         {
             FsEntry *const entry = *it;
             if (entry->root == oldDir &&
-                entry->type == FsEntryType::Zip)
+                entry->type == FsEntryType::Zip &&
+                entry->subDir == dirSeparator)
+            {
+                ZipEntry *const zipEntry = static_cast<ZipEntry*>(
+                    entry);
+                logger->log("Remove virtual zip: " + oldDir);
+                mEntries.erase(it);
+                delete zipEntry;
+                return true;
+            }
+        }
+
+        reportAlways("VirtFs::unmountZip not exists: %s",
+            oldDir.c_str());
+        return false;
+    }
+
+    bool unmountZip2(std::string oldDir,
+                     std::string subDir)
+    {
+        prepareFsPath(oldDir);
+        if (findLast(oldDir, ".zip") == false)
+        {
+            reportAlways("Called unmount without zip archive");
+            return false;
+        }
+        prepareFsPath(subDir);
+        FOR_EACH (std::vector<FsEntry*>::iterator, it, mEntries)
+        {
+            FsEntry *const entry = *it;
+            if (entry->root == oldDir &&
+                entry->type == FsEntryType::Zip &&
+                entry->subDir == subDir)
             {
                 ZipEntry *const zipEntry = static_cast<ZipEntry*>(
                     entry);
diff --git a/src/fs/virtfs/fs.h b/src/fs/virtfs/fs.h
index f8950723d..ccd5dcfdc 100644
--- a/src/fs/virtfs/fs.h
+++ b/src/fs/virtfs/fs.h
@@ -67,7 +67,12 @@ namespace VirtFs
                            std::string subDir);
     bool mountZip(std::string newDir,
                   const Append append);
+    bool mountZip2(std::string newDir,
+                   std::string subDir,
+                   const Append append);
     bool unmountZip(std::string oldDir);
+    bool unmountZip2(std::string oldDir,
+                     std::string subDir);
     std::string getRealDir(std::string filename);
     bool mkdir(const std::string &restrict dirName);
     bool remove(const std::string &restrict filename);
-- 
cgit v1.2.3-70-g09d2