Loading java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +1 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +33 −0 Original line number Diff line number Diff line Loading @@ -282,6 +282,39 @@ class BinaryDictionaryGetter { return result; } /** * 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. * Loading Loading
java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +1 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +33 −0 Original line number Diff line number Diff line Loading @@ -282,6 +282,39 @@ class BinaryDictionaryGetter { return result; } /** * 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. * Loading