From d3cac3443096c105cf1a1985677659105902cbdd Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 14 Dec 2015 15:53:25 -0800 Subject: updater: Use O_SYNC and fsync() for package_extract_file(). We are already using O_SYNC and fsync() for the recursive case (package_extract_dir()). Make it consistent for the single-file case. Bug: 20625549 Change-Id: I487736fe5a0647dd4a2428845e76bf642e0f0dff --- updater/install.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'updater') diff --git a/updater/install.cpp b/updater/install.cpp index e2b3db7ce..b09086964 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -555,14 +555,21 @@ Value* PackageExtractFileFn(const char* name, State* state, } { - FILE* f = fopen(dest_path, "wb"); - if (f == NULL) { - printf("%s: can't open %s for write: %s\n", - name, dest_path, strerror(errno)); + int fd = TEMP_FAILURE_RETRY(open(dest_path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, + S_IRUSR | S_IWUSR)); + if (fd == -1) { + printf("%s: can't open %s for write: %s\n", name, dest_path, strerror(errno)); goto done2; } - success = mzExtractZipEntryToFile(za, entry, fileno(f)); - fclose(f); + success = mzExtractZipEntryToFile(za, entry, fd); + if (fsync(fd) == -1) { + printf("fsync of \"%s\" failed: %s\n", dest_path, strerror(errno)); + success = false; + } + if (close(fd) == -1) { + printf("close of \"%s\" failed: %s\n", dest_path, strerror(errno)); + success = false; + } } done2: -- cgit v1.2.3