From 52ca82acf17488fb05ad1b528091616751fe3647 Mon Sep 17 00:00:00 2001 From: James Sanford Date: Thu, 8 Nov 2012 18:29:10 -0800 Subject: [PATCH] Move sync() to a different spot yet again. --- jni/android_driver.c | 2 +- src/com/froop/app/kegs/CopyHelper.java | 8 ++++++++ src/com/froop/app/kegs/diskimage/DiskLoader.java | 7 +------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jni/android_driver.c b/jni/android_driver.c index 3edcf42..9f9bc9e 100644 --- a/jni/android_driver.c +++ b/jni/android_driver.c @@ -263,7 +263,7 @@ void android_config_init(char *output, int maxlen) { } JNIEXPORT void JNICALL -Java_com_froop_app_kegs_DiskLoader_nativeSync( JNIEnv* env, jobject thiz) { +Java_com_froop_app_kegs_CopyHelper_nativeSync( JNIEnv* env, jobject thiz) { sync(); sync(); } diff --git a/src/com/froop/app/kegs/CopyHelper.java b/src/com/froop/app/kegs/CopyHelper.java index 0e48883..653e763 100644 --- a/src/com/froop/app/kegs/CopyHelper.java +++ b/src/com/froop/app/kegs/CopyHelper.java @@ -54,6 +54,7 @@ public class CopyHelper { if (mPreface != null) { out.write(mPreface, 0, mPreface.length); } + int totalread = 0; do { int numread = mInput.read(buf); if (numread <= 0) { @@ -61,11 +62,18 @@ public class CopyHelper { } else { out.write(buf, 0, numread); } + totalread += numread; } while (true); out.close(); + if (totalread > 400 * 1024) { + nativeSync(); + } output_file.renameTo(final_file); if (mClose) { mInput.close(); } } + + // See jni/android_driver.c:nativeSync() + private native void nativeSync(); } diff --git a/src/com/froop/app/kegs/diskimage/DiskLoader.java b/src/com/froop/app/kegs/diskimage/DiskLoader.java index edc14a0..ae59454 100644 --- a/src/com/froop/app/kegs/diskimage/DiskLoader.java +++ b/src/com/froop/app/kegs/diskimage/DiskLoader.java @@ -130,9 +130,7 @@ class DiskLoader extends AsyncTask { } protected Boolean doInBackground(Void... params) { - Boolean result = extractImage(); - nativeSync(); // Flush new disk images before claiming they are ready. - return result; + return extractImage(); } protected void onCancelled(final Boolean result) { @@ -142,7 +140,4 @@ class DiskLoader extends AsyncTask { protected void onPostExecute(final Boolean result) { mNotify.onImageReady(result, mImage); } - - // See jni/android_driver.c:nativeSync() - private native void nativeSync(); }