From 6d235fba1e76e16265219c8cc8a729003dd62e19 Mon Sep 17 00:00:00 2001 From: liulvping Date: Fri, 21 Jan 2022 10:13:19 +0800 Subject: add fsync when copy native libs In some low probability cases, after installing apps the device may restart without sync the storage, then the jni libs is damaged. The file size is ok, but the content all filled by 0x00. Bug: 214270558 Test: 1. adb install test.apk with jni libs 2. Enforce restart the device 3. check if the libs is damaged Change-Id: Ia82cfc0d3a14c729c9ac14b367b456d65e67e058 Signed-off-by: liulvping --- core/jni/com_android_internal_content_NativeLibraryHelper.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp index be82879c8411..0eb999f772d3 100644 --- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp +++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp @@ -260,6 +260,13 @@ copyFileIfChanged(JNIEnv *env, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntr return INSTALL_FAILED_CONTAINER_ERROR; } + if (fsync(fd) < 0) { + ALOGE("Coulnd't fsync temporary file name: %s: %s\n", localTmpFileName, strerror(errno)); + close(fd); + unlink(localTmpFileName); + return INSTALL_FAILED_INTERNAL_ERROR; + } + close(fd); // Set the modification time for this file to the ZIP's mod time. -- cgit v1.2.3-59-g8ed1b