AAPT2: Accept empty zip files
The libziparchive returns an error on empty zip files.
Work around this by checking for that error condition and
returning an empty ZipFileCollection.
Change-Id: I9edaf2e089456b6ccb4bb099b20ede10331bd352
diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp
index bf0f4aa..329dac9 100644
--- a/tools/aapt2/io/ZipArchive.cpp
+++ b/tools/aapt2/io/ZipArchive.cpp
@@ -75,11 +75,19 @@
std::unique_ptr<ZipFileCollection> ZipFileCollection::create(const StringPiece& path,
std::string* outError) {
+ constexpr static const int32_t kEmptyArchive = -6;
+
std::unique_ptr<ZipFileCollection> collection = std::unique_ptr<ZipFileCollection>(
new ZipFileCollection());
int32_t result = OpenArchive(path.data(), &collection->mHandle);
if (result != 0) {
+ // If a zip is empty, result will be an error code. This is fine and we should
+ // return an empty ZipFileCollection.
+ if (result == kEmptyArchive) {
+ return collection;
+ }
+
if (outError) *outError = ErrorCodeString(result);
return {};
}