Track crashing during migration to avoid crash loop.
Bug: 16213554 Bug: 16235703 Change-Id: Ib29b1a84b4c6ebae06d3dc6448f3c274ec6a7aab
This commit is contained in:
parent
a2087e66e5
commit
1d6024d2f8
1 changed files with 29 additions and 11 deletions
|
@ -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,22 +560,39 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
if (!isValidDictionary()) {
|
if (!isValidDictionary()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION;
|
final File isMigratingDir =
|
||||||
if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
close();
|
if (!isMigratingDir.mkdir()) {
|
||||||
final File dictFile = new File(mDictFilePath);
|
Log.e(TAG, "Cannot create a dir (" + isMigratingDir.getAbsolutePath()
|
||||||
final File tmpDictFile = new File(tmpDictFilePath);
|
+ ") to record migration.");
|
||||||
if (!FileUtils.deleteRecursively(dictFile)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!BinaryDictionaryUtils.renameDict(tmpDictFile, dictFile)) {
|
try {
|
||||||
return false;
|
final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION;
|
||||||
|
if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
final File dictFile = new File(mDictFilePath);
|
||||||
|
final File tmpDictFile = new File(tmpDictFilePath);
|
||||||
|
if (!FileUtils.deleteRecursively(dictFile)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!BinaryDictionaryUtils.renameDict(tmpDictFile, dictFile)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
loadDictionary(dictFile.getAbsolutePath(), 0 /* startOffset */,
|
||||||
|
dictFile.length(), mIsUpdatable);
|
||||||
|
return true;
|
||||||
|
} finally {
|
||||||
|
isMigratingDir.delete();
|
||||||
}
|
}
|
||||||
loadDictionary(dictFile.getAbsolutePath(), 0 /* startOffset */,
|
|
||||||
dictFile.length(), mIsUpdatable);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
|
|
Loading…
Reference in a new issue