diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-03-14 18:52:13 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-03-20 16:53:46 -0700 |
commit | 06460ef0d7072114ea3280e1650f77f55e7223f4 (patch) | |
tree | 5045dafbd896153c191ee0ea14717359021175e2 /tools/aapt2/LoadedApk.cpp | |
parent | 3910adfb62b6db705878058ccbae52af0fecb172 (diff) |
AAPT2: Fix up file IO
This also enables an AAPT behavior that CTS tests have
come to depend on.
Small files that compress negatively (get larger) are stored
uncompressed. Some CTS tests assume this and try to open these
files by mmapping them, which is only possible if they are
uncompressed.
Bug: 35461578
Test: make aapt2_tests
Change-Id: Id622a6150fe72477ad65d67d1bad897a8ee2ffb9
Diffstat (limited to 'tools/aapt2/LoadedApk.cpp')
-rw-r--r-- | tools/aapt2/LoadedApk.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp index 1d04b357131a..b855f8f80c58 100644 --- a/tools/aapt2/LoadedApk.cpp +++ b/tools/aapt2/LoadedApk.cpp @@ -20,6 +20,7 @@ #include "ValueVisitor.h" #include "flatten/Archive.h" #include "flatten/TableFlattener.h" +#include "io/BigBufferInputStream.h" namespace aapt { @@ -27,8 +28,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadApkFromPath(IAaptContext* context, const android::StringPiece& path) { Source source(path); std::string error; - std::unique_ptr<io::ZipFileCollection> apk = - io::ZipFileCollection::Create(path, &error); + std::unique_ptr<io::ZipFileCollection> apk = io::ZipFileCollection::Create(path, &error); if (!apk) { context->GetDiagnostics()->Error(DiagMessage(source) << error); return {}; @@ -36,21 +36,18 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadApkFromPath(IAaptContext* context, io::IFile* file = apk->FindFile("resources.arsc"); if (!file) { - context->GetDiagnostics()->Error(DiagMessage(source) - << "no resources.arsc found"); + context->GetDiagnostics()->Error(DiagMessage(source) << "no resources.arsc found"); return {}; } std::unique_ptr<io::IData> data = file->OpenAsData(); if (!data) { - context->GetDiagnostics()->Error(DiagMessage(source) - << "could not open resources.arsc"); + context->GetDiagnostics()->Error(DiagMessage(source) << "could not open resources.arsc"); return {}; } std::unique_ptr<ResourceTable> table = util::make_unique<ResourceTable>(); - BinaryResourceParser parser(context, table.get(), source, data->data(), - data->size()); + BinaryResourceParser parser(context, table.get(), source, data->data(), data->size()); if (!parser.Parse()) { return {}; } @@ -92,9 +89,9 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, const TableFlattenerOption continue; } - // The resource table needs to be reserialized since it might have changed. + // The resource table needs to be re-serialized since it might have changed. if (path == "resources.arsc") { - BigBuffer buffer = BigBuffer(1024); + BigBuffer buffer(4096); // TODO(adamlesinski): How to determine if there were sparse entries (and if to encode // with sparse entries) b/35389232. TableFlattener flattener(options, &buffer); @@ -102,8 +99,8 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, const TableFlattenerOption return false; } - if (!writer->StartEntry(path, ArchiveEntry::kAlign) || !writer->WriteEntry(buffer) || - !writer->FinishEntry()) { + io::BigBufferInputStream input_stream(&buffer); + if (!writer->WriteFile(path, ArchiveEntry::kAlign, &input_stream)) { context->GetDiagnostics()->Error(DiagMessage() << "Error when writing file '" << path << "' in APK."); return false; @@ -113,14 +110,12 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, const TableFlattenerOption std::unique_ptr<io::IData> data = file->OpenAsData(); uint32_t compression_flags = file->WasCompressed() ? ArchiveEntry::kCompress : 0u; - if (!writer->StartEntry(path, compression_flags) || - !writer->WriteEntry(data->data(), data->size()) || !writer->FinishEntry()) { + if (!writer->WriteFile(path, compression_flags, data.get())) { context->GetDiagnostics()->Error(DiagMessage() << "Error when writing file '" << path << "' in APK."); return false; } } - return true; } |