diff options
author | 2012-05-23 14:41:50 +0900 | |
---|---|---|
committer | 2012-05-23 15:59:49 +0900 | |
commit | b9e2bce95e955b6393c25226ab62fa44d24b904a (patch) | |
tree | 2bea4cb1264416d32a8a05023d728c30ebe4515b /java | |
parent | 37f81cd6e9a10fbdb3a1a054c88a6b5d98fb0f88 (diff) | |
download | latinime-b9e2bce95e955b6393c25226ab62fa44d24b904a.tar.gz latinime-b9e2bce95e955b6393c25226ab62fa44d24b904a.tar.xz latinime-b9e2bce95e955b6393c25226ab62fa44d24b904a.zip |
Remove an updated dictionary that changed locales
When a dictionary changes locale, we need to remove the file
that corresponds to the old version. It has a different path
than the new one, so we have to search for it explicitly.
Bug: 6540631
Change-Id: Ie9d63ba636651fe90f8fbb9627b7265ac7b34ccd
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java | 1 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index a4670daf2..d1ad4e170 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -193,6 +193,7 @@ public class BinaryDictionaryFileDumper { if (0 >= resolver.delete(wordListUri, null, null)) { Log.e(TAG, "Could not have the dictionary pack delete a word list"); } + BinaryDictionaryGetter.removeFilesWithIdExcept(context, id, outputFile); // Success! Close files (through the finally{} clause) and return. return AssetFileAddress.makeFromFileName(outputFileName); } catch (Exception e) { diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 5acd62904..063243e1b 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -283,6 +283,39 @@ class BinaryDictionaryGetter { } /** + * Remove all files with the passed id, except the passed file. + * + * If a dictionary with a given ID has a metadata change that causes it to change + * path, we need to remove the old version. The only way to do this is to check all + * installed files for a matching ID in a different directory. + */ + public static void removeFilesWithIdExcept(final Context context, final String id, + final File fileToKeep) { + try { + final File canonicalFileToKeep = fileToKeep.getCanonicalFile(); + final File[] directoryList = getCachedDirectoryList(context); + if (null == directoryList) return; + for (File directory : directoryList) { + // There is one directory per locale. See #getCachedDirectoryList + if (!directory.isDirectory()) continue; + final File[] wordLists = directory.listFiles(); + if (null == wordLists) continue; + for (File wordList : wordLists) { + final String fileId = getWordListIdFromFileName(wordList.getName()); + if (fileId.equals(id)) { + if (!canonicalFileToKeep.equals(wordList.getCanonicalFile())) { + wordList.delete(); + } + } + } + } + } catch (java.io.IOException e) { + Log.e(TAG, "IOException trying to cleanup files : " + e); + } + } + + + /** * Returns the id associated with the main word list for a specified locale. * * Word lists stored in Android Keyboard's resources are referred to as the "main" |