diff options
author | Tao Bao | 2015-12-15 11:55:05 -0600 |
---|---|---|
committer | Gerrit Code Review | 2015-12-15 11:55:05 -0600 |
commit | 4e72d1a81e2194caf101dc8633858efaa9bdb39b (patch) | |
tree | ebcae32374c84258018e995b10224c0f0eb6a78e | |
parent | e062645efa77ce3ab9ab802daee9e36b58e67bc4 (diff) | |
parent | d3cac3443096c105cf1a1985677659105902cbdd (diff) | |
download | platform-bootable-recovery-4e72d1a81e2194caf101dc8633858efaa9bdb39b.tar.gz platform-bootable-recovery-4e72d1a81e2194caf101dc8633858efaa9bdb39b.tar.xz platform-bootable-recovery-4e72d1a81e2194caf101dc8633858efaa9bdb39b.zip |
Merge "updater: Use O_SYNC and fsync() for package_extract_file()."
-rw-r--r-- | updater/install.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/updater/install.cpp b/updater/install.cpp index e2b3db7c..b0908696 100644 --- a/updater/install.cpp +++ b/updater/install.cpp | |||
@@ -555,14 +555,21 @@ Value* PackageExtractFileFn(const char* name, State* state, | |||
555 | } | 555 | } |
556 | 556 | ||
557 | { | 557 | { |
558 | FILE* f = fopen(dest_path, "wb"); | 558 | int fd = TEMP_FAILURE_RETRY(open(dest_path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, |
559 | if (f == NULL) { | 559 | S_IRUSR | S_IWUSR)); |
560 | printf("%s: can't open %s for write: %s\n", | 560 | if (fd == -1) { |
561 | name, dest_path, strerror(errno)); | 561 | printf("%s: can't open %s for write: %s\n", name, dest_path, strerror(errno)); |
562 | goto done2; | 562 | goto done2; |
563 | } | 563 | } |
564 | success = mzExtractZipEntryToFile(za, entry, fileno(f)); | 564 | success = mzExtractZipEntryToFile(za, entry, fd); |
565 | fclose(f); | 565 | if (fsync(fd) == -1) { |
566 | printf("fsync of \"%s\" failed: %s\n", dest_path, strerror(errno)); | ||
567 | success = false; | ||
568 | } | ||
569 | if (close(fd) == -1) { | ||
570 | printf("close of \"%s\" failed: %s\n", dest_path, strerror(errno)); | ||
571 | success = false; | ||
572 | } | ||
566 | } | 573 | } |
567 | 574 | ||
568 | done2: | 575 | done2: |