summaryrefslogtreecommitdiff
path: root/tools/aapt2/io/ZipArchive.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/io/ZipArchive.cpp')
-rw-r--r--tools/aapt2/io/ZipArchive.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp
index 269b6c5a12e1..427dc92505d4 100644
--- a/tools/aapt2/io/ZipArchive.cpp
+++ b/tools/aapt2/io/ZipArchive.cpp
@@ -20,6 +20,7 @@
#include "ziparchive/zip_archive.h"
#include "Source.h"
+#include "util/Files.h"
#include "util/Util.h"
using ::android::StringPiece;
@@ -32,6 +33,11 @@ ZipFile::ZipFile(ZipArchiveHandle handle, const ZipEntry& entry,
: zip_handle_(handle), zip_entry_(entry), source_(source) {}
std::unique_ptr<IData> ZipFile::OpenAsData() {
+ // The file will fail to be mmaped if it is empty
+ if (zip_entry_.uncompressed_length == 0) {
+ return util::make_unique<EmptyData>();
+ }
+
if (zip_entry_.method == kCompressStored) {
int fd = GetFileDescriptor(zip_handle_);
@@ -121,9 +127,14 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create(
std::string zip_entry_path =
std::string(reinterpret_cast<const char*>(zip_entry_name.name),
zip_entry_name.name_length);
- std::string nested_path = path.to_string() + "@" + zip_entry_path;
- std::unique_ptr<IFile> file =
- util::make_unique<ZipFile>(collection->handle_, zip_data, Source(nested_path));
+
+ // Do not add folders to the file collection
+ if (util::EndsWith(zip_entry_path, "/")) {
+ continue;
+ }
+
+ std::unique_ptr<IFile> file = util::make_unique<ZipFile>(collection->handle_, zip_data,
+ Source(zip_entry_path, path.to_string()));
collection->files_by_name_[zip_entry_path] = file.get();
collection->files_.push_back(std::move(file));
}
@@ -132,6 +143,7 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create(
if (out_error) *out_error = ErrorCodeString(result);
return {};
}
+
return collection;
}
@@ -147,6 +159,13 @@ std::unique_ptr<IFileCollectionIterator> ZipFileCollection::Iterator() {
return util::make_unique<ZipFileCollectionIterator>(this);
}
+char ZipFileCollection::GetDirSeparator() {
+ // According to the zip file specification, section 4.4.17.1:
+ // "All slashes MUST be forward slashes '/' as opposed to backwards slashes '\' for compatibility
+ // with Amiga and UNIX file systems etc."
+ return '/';
+}
+
ZipFileCollection::~ZipFileCollection() {
if (handle_) {
CloseArchive(handle_);