aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2015-08-04 21:01:11 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-04 21:01:11 +0000
commit5aa3ce3aaa12541d05fb613b4e74afe1f4d15171 (patch)
tree3e4a2460e7787042eaac1dd141ab6c2dd053f30f
parent6e9dda70cb00dd1f1948e071d7df7ca6e2bd8332 (diff)
parentbe19dce86ce7d4a83f1cfcd11db393f8be8f4397 (diff)
downloadbootable_recovery-5aa3ce3aaa12541d05fb613b4e74afe1f4d15171.zip
bootable_recovery-5aa3ce3aaa12541d05fb613b4e74afe1f4d15171.tar.gz
bootable_recovery-5aa3ce3aaa12541d05fb613b4e74afe1f4d15171.tar.bz2
am be19dce8: udpater: Call fsync() after rename().
* commit 'be19dce86ce7d4a83f1cfcd11db393f8be8f4397': udpater: Call fsync() after rename().
-rw-r--r--updater/blockimg.c20
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);
}