summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfszip.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-04 02:10:44 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-04 02:18:38 +0300
commitb625bb7201ba2633fe0247ad6a1577c3cd6860cb (patch)
tree8bc83dfe6b8cdad33d04ea593c50ee02b468c9fb /src/fs/virtfs/virtfszip.cpp
parent79bb654b80d5eb7a65814f80b9ca7ca1ccd62a00 (diff)
downloadmv-b625bb7201ba2633fe0247ad6a1577c3cd6860cb.tar.gz
mv-b625bb7201ba2633fe0247ad6a1577c3cd6860cb.tar.bz2
mv-b625bb7201ba2633fe0247ad6a1577c3cd6860cb.tar.xz
mv-b625bb7201ba2633fe0247ad6a1577c3cd6860cb.zip
Remove unused functions from virtfs.
Diffstat (limited to 'src/fs/virtfs/virtfszip.cpp')
-rw-r--r--src/fs/virtfs/virtfszip.cpp413
1 files changed, 4 insertions, 409 deletions
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp
index 881e028cc..eac4a2535 100644
--- a/src/fs/virtfs/virtfszip.cpp
+++ b/src/fs/virtfs/virtfszip.cpp
@@ -43,211 +43,18 @@ extern const char *dirSeparator;
namespace
{
- std::vector<VirtZipEntry*> mEntries;
VirtFsFuncs funcs;
} // namespace
namespace VirtFsZip
{
- VirtZipEntry *searchEntryByArchive(const std::string &restrict archiveName)
- {
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
- {
- if ((*it)->root == archiveName)
- return *it;
- }
- return nullptr;
- }
-
- ZipLocalHeader *searchHeaderByName(const std::string &restrict filename)
- {
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
- it2,
- entry->mHeaders)
- {
- if ((*it2)->fileName == filename)
- return *it2;
- }
- }
- return nullptr;
- }
-
- VirtZipEntry *searchZipEntryByNameWithDir(const std::string &restrict
- filename)
- {
- std::string dirName = filename;
- if (findLast(dirName, std::string(dirSeparator)) == false)
- dirName += dirSeparator;
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
- it2,
- entry->mHeaders)
- {
- if ((*it2)->fileName == filename)
- return entry;
- }
- FOR_EACH (std::vector<std::string>::const_iterator,
- it2,
- entry->mDirs)
- {
- if (*it2 == dirName)
- return entry;
- }
- }
- return nullptr;
- }
-
VirtFsFuncs *getFuncs()
{
return &funcs;
}
- bool addToSearchPathSilent(std::string newDir,
- const Append append)
- {
- prepareFsPath(newDir);
- if (Files::existsLocal(newDir) == false)
- {
- logger->log("VirtFsZip::addToSearchPath file not exists: %s",
- newDir.c_str());
- return false;
- }
- if (findLast(newDir, ".zip") == false)
- {
- reportAlways("Called VirtFsZip::addToSearchPath without "
- "zip archive");
- return false;
- }
- VirtZipEntry *entry = VirtFsZip::searchEntryByArchive(newDir);
- if (entry != nullptr)
- {
- reportAlways("VirtFsZip::addToSearchPath already exists: %s",
- newDir.c_str());
- return false;
- }
- entry = new VirtZipEntry(newDir, &funcs);
- if (Zip::readArchiveInfo(entry) == false)
- {
- delete entry;
- return false;
- }
-
- logger->log("Add virtual zip: " + newDir);
- if (append == Append_true)
- mEntries.push_back(entry);
- else
- {
- mEntries.insert(mEntries.begin(),
- entry);
- }
- return true;
- }
-
- bool addToSearchPath(std::string newDir,
- const Append append)
- {
- prepareFsPath(newDir);
- if (Files::existsLocal(newDir) == false)
- {
- reportAlways("VirtFsZip::addToSearchPath directory not exists: %s",
- newDir.c_str());
- return false;
- }
- if (findLast(newDir, ".zip") == false)
- {
- reportAlways("Called VirtFsZip::addToSearchPath without "
- "zip archive");
- return false;
- }
- VirtZipEntry *entry = VirtFsZip::searchEntryByArchive(newDir);
- if (entry != nullptr)
- {
- reportAlways("VirtFsZip::addToSearchPath already exists: %s",
- newDir.c_str());
- return false;
- }
- entry = new VirtZipEntry(newDir, &funcs);
- if (Zip::readArchiveInfo(entry) == false)
- {
- delete entry;
- return false;
- }
-
- logger->log("Add virtual zip: " + newDir);
- if (append == Append_true)
- mEntries.push_back(entry);
- else
- {
- mEntries.insert(mEntries.begin(),
- entry);
- }
- return true;
- }
-
- bool removeFromSearchPathSilent(std::string oldDir)
- {
- prepareFsPath(oldDir);
- if (findLast(oldDir, ".zip") == false)
- {
- reportAlways("Called removeFromSearchPath without zip archive");
- return false;
- }
- FOR_EACH (std::vector<VirtZipEntry*>::iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- if (entry->root == oldDir)
- {
- logger->log("Remove virtual zip: " + oldDir);
- mEntries.erase(it);
- delete entry;
- return true;
- }
- }
-
- logger->log("VirtFsZip::removeFromSearchPath not exists: %s",
- oldDir.c_str());
- return false;
- }
-
- bool removeFromSearchPath(std::string oldDir)
- {
- prepareFsPath(oldDir);
- if (findLast(oldDir, ".zip") == false)
- {
- reportAlways("Called removeFromSearchPath without zip archive");
- return false;
- }
- FOR_EACH (std::vector<VirtZipEntry*>::iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- if (entry->root == oldDir)
- {
- logger->log("Remove virtual zip: " + oldDir);
- mEntries.erase(it);
- delete entry;
- return true;
- }
- }
-
- reportAlways("VirtFsZip::removeFromSearchPath not exists: %s",
- oldDir.c_str());
- return false;
- }
-
- std::vector<VirtZipEntry*> &getEntries()
- {
- return mEntries;
- }
-
void deinit()
{
- delete_all(mEntries);
- mEntries.clear();
}
void init()
@@ -273,27 +80,6 @@ namespace VirtFsZip
ptr->openAppend = &VirtFsZip::openAppend;
}
- std::string getRealDir(std::string filename)
- {
- prepareFsPath(filename);
- if (checkPath(filename) == false)
- {
- reportAlways("VirtFsZip::exists invalid path: %s",
- filename.c_str());
- return std::string();
- }
- return getRealDirInternal(filename);
- }
-
- std::string getRealDirInternal(const std::string &filename)
- {
- VirtZipEntry *restrict const entry = searchZipEntryByNameWithDir(
- filename);
- if (entry != nullptr)
- return entry->root;
- return std::string();
- }
-
bool getRealDir(VirtFsEntry *restrict const entry,
const std::string &filename,
const std::string &dirName,
@@ -323,20 +109,6 @@ namespace VirtFsZip
return false;
}
- bool exists(std::string name)
- {
- prepareFsPath(name);
- if (checkPath(name) == false)
- {
- reportAlways("VirtFsZip::exists invalid path: %s",
- name.c_str());
- return false;
- }
- VirtZipEntry *restrict const entry = searchZipEntryByNameWithDir(
- name);
- return entry != nullptr;
- }
-
bool exists(VirtFsEntry *restrict const entry,
const std::string &filename,
const std::string &dirName)
@@ -359,19 +131,6 @@ namespace VirtFsZip
return false;
}
- VirtList *enumerateFiles(std::string dirName)
- {
- VirtList *const list = new VirtList;
- prepareFsPath(dirName);
- if (checkPath(dirName) == false)
- {
- reportAlways("VirtFsZip::enumerateFiles invalid path: %s",
- dirName.c_str());
- return list;
- }
- return enumerateFiles(dirName, list);
- }
-
void enumerate(VirtFsEntry *restrict const entry,
const std::string &dirName,
StringVect &names)
@@ -432,77 +191,6 @@ namespace VirtFsZip
}
}
- VirtList *enumerateFiles(std::string dirName,
- VirtList *restrict const list)
- {
- if (findLast(dirName, std::string(dirSeparator)) == false)
- dirName += dirSeparator;
- StringVect &names = list->names;
- if (dirName == "/")
- {
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
- it2,
- entry->mHeaders)
- {
- ZipLocalHeader *const header = *it2;
- std::string fileName = header->fileName;
- // skip subdirs from enumeration
- const size_t idx = fileName.find(dirSeparator);
- if (idx != std::string::npos)
- fileName.erase(idx);
- bool found(false);
- FOR_EACH (StringVectCIter, itn, names)
- {
- if (*itn == fileName)
- {
- found = true;
- break;
- }
- }
- if (found == false)
- names.push_back(fileName);
- }
- }
- }
- else
- {
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
- it2,
- entry->mHeaders)
- {
- ZipLocalHeader *const header = *it2;
- std::string fileName = header->fileName;
- if (findCutFirst(fileName, dirName) == true)
- {
- // skip subdirs from enumeration
- const size_t idx = fileName.find(dirSeparator);
- if (idx != std::string::npos)
- fileName.erase(idx);
- bool found(false);
- FOR_EACH (StringVectCIter, itn, names)
- {
- if (*itn == fileName)
- {
- found = true;
- break;
- }
- }
- if (found == false)
- names.push_back(fileName);
- }
- }
- }
- }
-
- return list;
- }
-
bool isDirectory(VirtFsEntry *restrict const entry,
const std::string &dirName,
bool &isDirFlag)
@@ -521,54 +209,11 @@ namespace VirtFsZip
return false;
}
- bool isDirectoryInternal(std::string dirName)
- {
- if (findLast(dirName, std::string(dirSeparator)) == false)
- dirName += dirSeparator;
- FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
- {
- VirtZipEntry *const entry = *it;
- FOR_EACH (std::vector<std::string>::const_iterator,
- it2,
- entry->mDirs)
- {
- if (*it2 == dirName)
- return true;
- }
- }
- return false;
- }
-
- bool isSymbolicLink(std::string name)
- {
- prepareFsPath(name);
- if (checkPath(name) == false)
- {
- reportAlways("VirtFsZip::isSymbolicLink invalid path: %s",
- name.c_str());
- return false;
- }
- // look like in zip files can be symlinks, but here they useless
- return false;
- }
-
void freeList(VirtList *restrict const handle)
{
delete handle;
}
- VirtFile *openRead(std::string filename)
- {
- prepareFsPath(filename);
- if (checkPath(filename) == false)
- {
- reportAlways("VirtFsZip::openRead invalid path: %s",
- filename.c_str());
- return nullptr;
- }
- return openReadInternal(filename);
- }
-
VirtFile *openRead(VirtFsEntry *restrict const entry,
const std::string &filename)
{
@@ -592,70 +237,20 @@ namespace VirtFsZip
return nullptr;
}
- VirtFile *openWrite(VirtFsEntry *restrict const entry,
- const std::string &filename)
+ VirtFile *openWrite(VirtFsEntry *restrict const entry A_UNUSED,
+ const std::string &filename A_UNUSED)
{
reportAlways("VirtFs::openWrite for zip not implemented.");
return nullptr;
}
- VirtFile *openAppend(VirtFsEntry *restrict const entry,
- const std::string &filename)
+ VirtFile *openAppend(VirtFsEntry *restrict const entry A_UNUSED,
+ const std::string &filename A_UNUSED)
{
reportAlways("VirtFs::openAppend for zip not implemented.");
return nullptr;
}
- VirtFile *openReadInternal(const std::string &filename)
- {
- ZipLocalHeader *restrict const header = searchHeaderByName(filename);
- if (header != nullptr)
- {
- uint8_t *restrict const buf = Zip::readFile(header);
- if (buf == nullptr)
- return nullptr;
- VirtFile *restrict const file = new VirtFile(&funcs);
- file->mPrivate = new VirtFilePrivate(buf,
- header->uncompressSize);
- return file;
- }
- return nullptr;
- }
-
- VirtFile *openWrite(const std::string &restrict filename A_UNUSED)
- {
- return nullptr;
- }
-
- VirtFile *openAppend(const std::string &restrict filename A_UNUSED)
- {
- return nullptr;
- }
-
- bool setWriteDir(const std::string &restrict newDir A_UNUSED)
- {
- return false;
- }
-
- bool mkdir(const std::string &restrict dirname A_UNUSED)
- {
- return false;
- }
-
- bool remove(const std::string &restrict filename A_UNUSED)
- {
- return false;
- }
-
- void permitLinks(const bool val A_UNUSED)
- {
- }
-
- const char *getLastError()
- {
- return nullptr;
- }
-
int close(VirtFile *restrict const file)
{
if (file == nullptr)