Skip to content

Commit 042c3cd

Browse files
author
Michael Runge
committed
Force sync files written by minzip.
Some files appear to be missing their sync to disk. Bug: 18145574 Change-Id: Ic858624a4dd65bbfc54d30f3a13c607078270345
1 parent 5ddf429 commit 042c3cd

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)