From dc3922622a94af4f6412fd68e8f075f839ab2348 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 31 Jul 2015 15:56:44 -0700 Subject: udpater: Call fsync() after rename(). We need to ensure the renamed filename reaches the underlying storage. Bug: 22840552 Change-Id: Ide2e753a2038691d472b6ee173cbf68ac998a084 --- updater/blockimg.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 77117db05..a7821f362 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -686,6 +687,7 @@ static int WriteStash(const char* base, const char* id, int blocks, uint8_t* buf char *cn = NULL; int fd = -1; int rc = -1; + int dfd = -1; int res; struct stat st; @@ -744,6 +746,20 @@ static int WriteStash(const char* base, const char* id, int blocks, uint8_t* buf goto wsout; } + const char* dname; + dname = dirname(cn); + dfd = TEMP_FAILURE_RETRY(open(dname, O_RDONLY | O_DIRECTORY)); + + if (dfd == -1) { + fprintf(stderr, "failed to open \"%s\" failed: %s\n", dname, strerror(errno)); + goto wsout; + } + + if (fsync(dfd) == -1) { + fprintf(stderr, "fsync \"%s\" failed: %s\n", dname, strerror(errno)); + goto wsout; + } + rc = 0; wsout: @@ -751,6 +767,10 @@ wsout: close(fd); } + if (dfd != -1) { + close(dfd); + } + if (fn) { free(fn); } -- cgit v1.2.3