diff options
author | MÃ¥rten Kongstad <marten.kongstad@volvocars.com> | 2021-05-10 08:34:54 +0000 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2021-06-02 19:33:50 +0000 |
commit | a384fb763717ac0b841605b0b16b23784c09fc90 (patch) | |
tree | 045c2b6fbfc35e9ce67f48ffd2c5bcf72419d764 /cmds/idmap2/idmap2d/Idmap2Service.cpp | |
parent | 2db6ff2c70c2d6e88ed8059f679bd9d264c65009 (diff) |
idmap2: create in-memory FRRO before creating file
Re-order the serialization of an FRRO and creation of the backing file.
This prevents a dangling (empty) file if the serialization fails.
Bug: 189963636
Test: manual: cmd overlay fabricate <bad parameters>, verify no file created in /data/resource-cache
Change-Id: I1af88c6d2d1c3a881beecfb50ccaf541a249f39b
Diffstat (limited to 'cmds/idmap2/idmap2d/Idmap2Service.cpp')
-rw-r--r-- | cmds/idmap2/idmap2d/Idmap2Service.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp index 05336baf9217..4f775aa52195 100644 --- a/cmds/idmap2/idmap2d/Idmap2Service.cpp +++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp @@ -262,17 +262,17 @@ Status Idmap2Service::createFabricatedOverlay( path.c_str(), uid)); } + const auto frro = builder.Build(); + if (!frro) { + return error(StringPrintf("failed to serialize '%s:%s': %s", overlay.packageName.c_str(), + overlay.overlayName.c_str(), frro.GetErrorMessage().c_str())); + } // Persist the fabricated overlay. umask(kIdmapFilePermissionMask); std::ofstream fout(path); if (fout.fail()) { return error("failed to open frro path " + path); } - const auto frro = builder.Build(); - if (!frro) { - return error(StringPrintf("failed to serialize '%s:%s': %s", overlay.packageName.c_str(), - overlay.overlayName.c_str(), frro.GetErrorMessage().c_str())); - } auto result = frro->ToBinaryStream(fout); if (!result) { unlink(path.c_str()); |