ART: Save or erase the file even if I/O failed
It should close the file in any case.
Change-Id: Idb7db15bfecb0ac47839be3544cc2dce91096d7b
Signed-off-by: Serdjuk, Nikolay Y <nikolay.y.serdjuk@intel.com>
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index 63ae342..a1b3c9e 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -320,11 +320,11 @@
PatchOat& p = space_to_patchoat_map.find(space)->second;
- if (!p.WriteImage(output_image_file.get())) {
- LOG(ERROR) << "Failed to write image file " << output_image_file->GetPath();
+ bool success = p.WriteImage(output_image_file.get());
+ success = FinishFile(output_image_file.get(), success);
+ if (!success) {
return false;
}
- FinishFile(output_image_file.get(), true);
bool skip_patching_oat = space_to_skip_patching_map.find(space)->second;
if (!skip_patching_oat) {
@@ -336,11 +336,11 @@
LOG(ERROR) << "Failed to open output oat file at " << output_oat_filename;
return false;
}
- if (!p.WriteElf(output_oat_file.get())) {
- LOG(ERROR) << "Failed to write oat file " << output_oat_file->GetPath();
+ success = p.WriteElf(output_oat_file.get());
+ success = FinishFile(output_oat_file.get(), success);
+ if (!success) {
return false;
}
- FinishFile(output_oat_file.get(), true);
}
}
return true;