diff options
author | Andreas Gampe <agampe@google.com> | 2014-11-06 01:00:46 -0800 |
---|---|---|
committer | Andreas Gampe <agampe@google.com> | 2014-11-18 17:26:06 -0800 |
commit | 4303ba97313458491e038d78efa041d41cf7bb43 (patch) | |
tree | 5a5873651db918416c9ff63f4bb06b6eb7f4c71a /patchoat | |
parent | a971100be7870544360fa8a46311ef7f5adb6902 (diff) | |
download | art-4303ba97313458491e038d78efa041d41cf7bb43.zip art-4303ba97313458491e038d78efa041d41cf7bb43.tar.gz art-4303ba97313458491e038d78efa041d41cf7bb43.tar.bz2 |
ART: Track Flush & Close in FdFile
Implement a check that aborts when a file hasn't been explicitly
flushed and closed when it is destructed.
Add WARN_UNUSED to FdFile methods.
Update dex2oat, patchoat, scoped_flock and some gtests to pass with
this.
(cherry picked from commit 9433ec60b325b708b9fa87e699ab4a6565741494)
Change-Id: I9ab03b1653e69f44cc98946dc89d764c3e045dd4
Diffstat (limited to 'patchoat')
-rw-r--r-- | patchoat/patchoat.cc | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index 281649e..b15c712 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -904,6 +904,20 @@ static File* CreateOrOpen(const char* name, bool* created) { } } +// Either try to close the file (close=true), or erase it. +static bool FinishFile(File* file, bool close) { + if (close) { + if (file->FlushCloseOrErase() != 0) { + PLOG(ERROR) << "Failed to flush and close file."; + return false; + } + return true; + } else { + file->Erase(); + return false; + } +} + static int patchoat(int argc, char **argv) { InitLogging(argv); MemMap::Init(); @@ -1175,7 +1189,7 @@ static int patchoat(int argc, char **argv) { if (output_image_filename.empty()) { output_image_filename = "output-image-file"; } - output_image.reset(new File(output_image_fd, output_image_filename)); + output_image.reset(new File(output_image_fd, output_image_filename, true)); } else { CHECK(!output_image_filename.empty()); output_image.reset(CreateOrOpen(output_image_filename.c_str(), &new_image_out)); @@ -1189,7 +1203,7 @@ static int patchoat(int argc, char **argv) { if (input_oat_filename.empty()) { input_oat_filename = "input-oat-file"; } - input_oat.reset(new File(input_oat_fd, input_oat_filename)); + input_oat.reset(new File(input_oat_fd, input_oat_filename, false)); if (input_oat == nullptr) { // Unlikely, but ensure exhaustive logging in non-0 exit code case LOG(ERROR) << "Failed to open input oat file by its FD" << input_oat_fd; @@ -1208,7 +1222,7 @@ static int patchoat(int argc, char **argv) { if (output_oat_filename.empty()) { output_oat_filename = "output-oat-file"; } - output_oat.reset(new File(output_oat_fd, output_oat_filename)); + output_oat.reset(new File(output_oat_fd, output_oat_filename, true)); if (output_oat == nullptr) { // Unlikely, but ensure exhaustive logging in non-0 exit code case LOG(ERROR) << "Failed to open output oat file by its FD" << output_oat_fd; @@ -1281,14 +1295,20 @@ static int patchoat(int argc, char **argv) { output_oat.get(), output_image.get(), isa, &timings, output_oat_fd >= 0, // was it opened from FD? new_oat_out); + // The order here doesn't matter. If the first one is successfully saved and the second one + // erased, ImageSpace will still detect a problem and not use the files. + ret = ret && FinishFile(output_image.get(), ret); + ret = ret && FinishFile(output_oat.get(), ret); } else if (have_oat_files) { TimingLogger::ScopedTiming pt("patch oat", &timings); ret = PatchOat::Patch(input_oat.get(), base_delta, output_oat.get(), &timings, output_oat_fd >= 0, // was it opened from FD? new_oat_out); + ret = ret && FinishFile(output_oat.get(), ret); } else if (have_image_files) { TimingLogger::ScopedTiming pt("patch image", &timings); ret = PatchOat::Patch(input_image_location, base_delta, output_image.get(), isa, &timings); + ret = ret && FinishFile(output_image.get(), ret); } else { CHECK(false); ret = true; |