Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aa3ce3a authored by Tao Bao's avatar Tao Bao Committed by Android Git Automerger
Browse files

am be19dce8: udpater: Call fsync() after rename().

* commit 'be19dce8':
  udpater: Call fsync() after rename().
parents 6e9dda70 be19dce8
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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);
    }