Merge "udpater: Call fsync() after rename()."
This commit is contained in:
commit
27c1ab2095
1 changed files with 20 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -686,6 +687,7 @@ static int WriteStash(const char* base, const char* id, int blocks, uint8_t* buf
|
||||||
char *cn = NULL;
|
char *cn = NULL;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
int dfd = -1;
|
||||||
int res;
|
int res;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
@ -744,6 +746,20 @@ static int WriteStash(const char* base, const char* id, int blocks, uint8_t* buf
|
||||||
goto wsout;
|
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;
|
rc = 0;
|
||||||
|
|
||||||
wsout:
|
wsout:
|
||||||
|
@ -751,6 +767,10 @@ wsout:
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dfd != -1) {
|
||||||
|
close(dfd);
|
||||||
|
}
|
||||||
|
|
||||||
if (fn) {
|
if (fn) {
|
||||||
free(fn);
|
free(fn);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue