diff options
author | Tao Bao <tbao@google.com> | 2015-07-31 15:56:44 -0700 |
---|---|---|
committer | Tao Bao <tbao@google.com> | 2015-08-04 11:28:12 -0700 |
commit | be19dce86ce7d4a83f1cfcd11db393f8be8f4397 (patch) | |
tree | d2ec0f2824909fc62b5f235ed4ccbbff56f67f59 | |
parent | 10cf0942a7f4b2bfd539416e4767aaaf866a6527 (diff) | |
download | bootable_recovery-be19dce86ce7d4a83f1cfcd11db393f8be8f4397.zip bootable_recovery-be19dce86ce7d4a83f1cfcd11db393f8be8f4397.tar.gz bootable_recovery-be19dce86ce7d4a83f1cfcd11db393f8be8f4397.tar.bz2 |
udpater: Call fsync() after rename().
We need to ensure the renamed filename reaches the underlying storage.
Bug: 22840552
Change-Id: I824b6e9d8a9c5966035be7b42a73678d07376342
(cherry picked from commit dc3922622a94af4f6412fd68e8f075f839ab2348)
-rw-r--r-- | updater/blockimg.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/updater/blockimg.c b/updater/blockimg.c index 5b8a6a3..b006d10 100644 --- a/updater/blockimg.c +++ b/updater/blockimg.c @@ -19,6 +19,7 @@ #include <dirent.h> #include <fcntl.h> #include <inttypes.h> +#include <libgen.h> #include <pthread.h> #include <stdarg.h> #include <stdio.h> @@ -632,6 +633,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; @@ -690,6 +692,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: @@ -697,6 +713,10 @@ wsout: close(fd); } + if (dfd != -1) { + close(dfd); + } + if (fn) { free(fn); } |