Skip to content

Commit e908a45

Browse files
Michael RungeAndroid Git Automerger
authored andcommitted
am 042c3cd: Force sync files written by minzip.
* commit '042c3cd04ec3ef416019fa382cd5b1a942bd79e1': Force sync files written by minzip.
2 parents fe8563f + 042c3cd commit e908a45

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

minzip/Zip.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
10671067
setfscreatecon(secontext);
10681068
}
10691069

1070-
int fd = creat(targetFile, UNZIP_FILEMODE);
1070+
int fd = open(targetFile, O_CREAT|O_WRONLY|O_TRUNC|O_SYNC
1071+
, UNZIP_FILEMODE);
10711072

10721073
if (secontext) {
10731074
freecon(secontext);
@@ -1082,7 +1083,12 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
10821083
}
10831084

10841085
bool ok = mzExtractZipEntryToFile(pArchive, pEntry, fd);
1085-
close(fd);
1086+
if (ok) {
1087+
ok = (fsync(fd) == 0);
1088+
}
1089+
if (close(fd) != 0) {
1090+
ok = false;
1091+
}
10861092
if (!ok) {
10871093
LOGE("Error extracting \"%s\"\n", targetFile);
10881094
ok = false;

0 commit comments

Comments
 (0)