Move sync() to a different spot yet again.

This commit is contained in:
James Sanford 2012-11-08 18:29:10 -08:00
parent 8a977116c2
commit 52ca82acf1
3 changed files with 10 additions and 7 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -130,9 +130,7 @@ class DiskLoader extends AsyncTask<Void, Void, Boolean> {
}
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<Void, Void, Boolean> {
protected void onPostExecute(final Boolean result) {
mNotify.onImageReady(result, mImage);
}
// See jni/android_driver.c:nativeSync()
private native void nativeSync();
}