summaryrefslogtreecommitdiff
path: root/src/fs/zip.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-25 19:10:51 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-25 19:11:57 +0300
commite6198149823ee18e4167b0e6dd34cfb7f2e2f496 (patch)
tree013181d9d8e4f06433838cffaabf6159aa2f775b /src/fs/zip.cpp
parent0bb68a88e6dc6a04685825e80b4e3dca1dc097d2 (diff)
downloadmv-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.tar.gz
mv-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.tar.bz2
mv-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.tar.xz
mv-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.zip
Implement basic VirtFsZip for virtual fs based on zip archives.
Api similar to VirtFs. For now unused.
Diffstat (limited to 'src/fs/zip.cpp')
-rw-r--r--src/fs/zip.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/fs/zip.cpp b/src/fs/zip.cpp
index cff4a3e6f..62b60a451 100644
--- a/src/fs/zip.cpp
+++ b/src/fs/zip.cpp
@@ -20,7 +20,7 @@
#include "fs/zip.h"
-#include "fs/virtfile.h"
+#include "fs/virtzipentry.h"
#include "fs/ziplocalheader.h"
#include "utils/checkutils.h"
@@ -46,9 +46,16 @@
namespace Zip
{
- bool readArchiveInfo(const std::string &restrict archiveName,
- std::vector<ZipLocalHeader*> &restrict headers)
+ bool readArchiveInfo(VirtZipEntry *const entry)
{
+ if (entry == nullptr)
+ {
+ reportAlways("Entry is null.");
+ return false;
+ }
+ const std::string archiveName = entry->mArchiveName;
+ std::vector<ZipLocalHeader*> &restrict headers = entry->mHeaders;
+ std::vector<std::string> &restrict dirs = entry->mDirs;
FILE *restrict const arcFile = fopen(archiveName.c_str(),
"r");
if (arcFile == nullptr)
@@ -78,7 +85,7 @@ namespace Zip
buf[3] == 0x04)
{ // local file header
header = new ZipLocalHeader;
- header->archiveName = archiveName;
+ header->zipEntry = entry;
// skip useless fields
fseek(arcFile, 4, SEEK_CUR); // + 4
// file header pointer on 8
@@ -131,6 +138,11 @@ namespace Zip
logger->log(" uncompressed size: %u",
header->uncompressSize);
}
+ else
+ {
+ dirs.push_back(header->fileName);
+ delete header;
+ }
}
else if (buf[0] == 0x50 &&
buf[1] == 0x4B &&
@@ -197,12 +209,13 @@ namespace Zip
reportAlways("Zip::readCompressedFile: header is null");
return nullptr;
}
- FILE *restrict const arcFile = fopen(header->archiveName.c_str(),
+ FILE *restrict const arcFile = fopen(
+ header->zipEntry->mArchiveName.c_str(),
"r");
if (arcFile == nullptr)
{
reportAlways("Can't open zip file %s",
- header->archiveName.c_str());
+ header->zipEntry->mArchiveName.c_str());
return nullptr;
}
@@ -213,7 +226,7 @@ namespace Zip
compressSize)
{
reportAlways("Read zip compressed file error from archive: %s",
- header->archiveName.c_str());
+ header->zipEntry->mArchiveName.c_str());
fclose(arcFile);
delete [] buf;
return nullptr;
@@ -251,7 +264,7 @@ namespace Zip
int ret = inflateInit2(&strm, -MAX_WBITS);
if (ret != Z_OK)
{
- reportZlibError(header->archiveName, ret);
+ reportZlibError(header->zipEntry->mArchiveName, ret);
delete [] in;
delete [] out;
return nullptr;