diff options
| author | Adam Lesinski <adamlesinski@google.com> | 2017-04-24 15:09:32 -0700 |
|---|---|---|
| committer | Adam Lesinski <adamlesinski@google.com> | 2017-04-24 22:19:53 +0000 |
| commit | 776aa959c7122f23f3c58443ea1b673127ed01f2 (patch) | |
| tree | 39be8ea438a97a730ff65bf052e234576b4e0ad3 /tools/aapt2/cmd/Compile.cpp | |
| parent | 57b999605c373b4798f29174c0fddb47ddc2c263 (diff) | |
AAPT2: Add better error message when processing invalid files
Instead of showing a failed mmap error, show a better error when a file
being compiled is a directory or other unsupported file type.
Bug: 37626838
Test: manual
Change-Id: Ib9acf5f48ab5da37e79411c6a9f37c51f00f925f
Diffstat (limited to 'tools/aapt2/cmd/Compile.cpp')
| -rw-r--r-- | tools/aapt2/cmd/Compile.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp index 578a8fb423dc..9da0215cde51 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -365,6 +365,21 @@ static bool FlattenXmlToOutStream(IAaptContext* context, const StringPiece& outp return true; } +static bool IsValidFile(IAaptContext* context, const StringPiece& input_path) { + const file::FileType file_type = file::GetFileType(input_path); + if (file_type != file::FileType::kRegular && file_type != file::FileType::kSymlink) { + if (file_type == file::FileType::kDirectory) { + context->GetDiagnostics()->Error(DiagMessage(input_path) + << "resource file cannot be a directory"); + } else { + context->GetDiagnostics()->Error(DiagMessage(input_path) + << "not a valid resource file"); + } + return false; + } + return true; +} + static bool CompileXml(IAaptContext* context, const CompileOptions& options, const ResourcePathData& path_data, IArchiveWriter* writer, const std::string& output_path) { @@ -569,7 +584,8 @@ static bool CompileFile(IAaptContext* context, const CompileOptions& options, std::string error_str; Maybe<android::FileMap> f = file::MmapPath(path_data.source.path, &error_str); if (!f) { - context->GetDiagnostics()->Error(DiagMessage(path_data.source) << error_str); + context->GetDiagnostics()->Error(DiagMessage(path_data.source) << "failed to mmap file: " + << error_str); return false; } @@ -692,6 +708,11 @@ int Compile(const std::vector<StringPiece>& args) { context.GetDiagnostics()->Note(DiagMessage(path_data.source) << "processing"); } + if (!IsValidFile(&context, path_data.source.path)) { + error = true; + continue; + } + if (path_data.resource_dir == "values") { // Overwrite the extension. path_data.extension = "arsc"; |
