am 1d6024d2: Track crashing during migration to avoid crash loop.

* commit '1d6024d2f8051271e3c9abc1285d989114f5f1d7':
  Track crashing during migration to avoid crash loop.
main
Keisuke Kuroyanagi 2014-07-14 07:35:01 +00:00 committed by Android Git Automerger
commit 3cd5801bd6
1 changed files with 29 additions and 11 deletions

View File

@ -80,6 +80,7 @@ public final class BinaryDictionary extends Dictionary {
public static final int FORMAT_WORD_PROPERTY_COUNT_INDEX = 3; public static final int FORMAT_WORD_PROPERTY_COUNT_INDEX = 3;
public static final String DICT_FILE_NAME_SUFFIX_FOR_MIGRATION = ".migrate"; public static final String DICT_FILE_NAME_SUFFIX_FOR_MIGRATION = ".migrate";
public static final String DIR_NAME_SUFFIX_FOR_RECORD_MIGRATION = ".migrating";
private long mNativeDict; private long mNativeDict;
private final Locale mLocale; private final Locale mLocale;
@ -559,6 +560,20 @@ public final class BinaryDictionary extends Dictionary {
if (!isValidDictionary()) { if (!isValidDictionary()) {
return false; return false;
} }
final File isMigratingDir =
new File(mDictFilePath + DIR_NAME_SUFFIX_FOR_RECORD_MIGRATION);
if (isMigratingDir.exists()) {
isMigratingDir.delete();
Log.e(TAG, "Previous migration attempt failed probably due to a crash. "
+ "Giving up using the old dictionary (" + mDictFilePath + ").");
return false;
}
if (!isMigratingDir.mkdir()) {
Log.e(TAG, "Cannot create a dir (" + isMigratingDir.getAbsolutePath()
+ ") to record migration.");
return false;
}
try {
final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION; final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION;
if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) { if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) {
return false; return false;
@ -575,6 +590,9 @@ public final class BinaryDictionary extends Dictionary {
loadDictionary(dictFile.getAbsolutePath(), 0 /* startOffset */, loadDictionary(dictFile.getAbsolutePath(), 0 /* startOffset */,
dictFile.length(), mIsUpdatable); dictFile.length(), mIsUpdatable);
return true; return true;
} finally {
isMigratingDir.delete();
}
} }
@UsedForTesting @UsedForTesting