diff options
Diffstat (limited to 'native/jni/src')
4 files changed, 26 insertions, 5 deletions
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index 9a26fe051..1969ebae0 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -87,12 +87,21 @@ AK_FORCE_INLINE static int intArrayToCharArray(const int *const source, const in } #if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG) +#if defined(__ANDROID__) #include <android/log.h> +#endif // defined(__ANDROID__) #ifndef LOG_TAG #define LOG_TAG "LatinIME: " #endif // LOG_TAG + +#if defined(HOST_TOOL) +#include <stdio.h> +#define AKLOGE(fmt, ...) printf(fmt "\n", ##__VA_ARGS__) +#define AKLOGI(fmt, ...) printf(fmt "\n", ##__VA_ARGS__) +#else // defined(HOST_TOOL) #define AKLOGE(fmt, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##__VA_ARGS__) #define AKLOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##__VA_ARGS__) +#endif // defined(HOST_TOOL) #define DUMP_RESULT(words, frequencies) do { dumpResult(words, frequencies); } while (0) #define DUMP_WORD(word, length) do { dumpWord(word, length); } while (0) diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.cpp index 34fecc25f..9afb5f221 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.cpp @@ -33,8 +33,7 @@ const char *const Ver4DictConstants::SHORTCUT_CONTENT_TABLE_FILE_EXTENSION = ".shortcut_index_shortcut"; // Version 4 dictionary size is implicitly limited to 8MB due to 3-byte offsets. -// TODO: Make MAX_DICTIONARY_SIZE 8MB. -const int Ver4DictConstants::MAX_DICTIONARY_SIZE = 2 * 1024 * 1024; +const int Ver4DictConstants::MAX_DICTIONARY_SIZE = 8 * 1024 * 1024; // Extended region size, which is not GCed region size in dict file + additional buffer size, is // limited to 1MB to prevent from inefficient traversing. const int Ver4DictConstants::MAX_DICT_EXTENDED_REGION_SIZE = 1 * 1024 * 1024; diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp index 1f25cfa1e..9441a75fc 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp @@ -53,6 +53,11 @@ namespace latinime { // Remove a directory and all files in the directory. /* static */ bool FileUtils::removeDirAndFiles(const char *const dirPath) { + return removeDirAndFiles(dirPath, 5 /* maxTries */); +} + +// Remove a directory and all files in the directory, trying up to maxTimes. +/* static */ bool FileUtils::removeDirAndFiles(const char *const dirPath, const int maxTries) { DIR *const dir = opendir(dirPath); if (dir == NULL) { AKLOGE("Cannot open dir %s.", dirPath); @@ -60,7 +65,7 @@ namespace latinime { } struct dirent *dirent; while ((dirent = readdir(dir)) != NULL) { - if (dirent->d_type != DT_REG) { + if (dirent->d_type == DT_DIR) { continue; } const int filePathBufSize = getFilePathBufSize(dirPath, dirent->d_name); @@ -74,8 +79,14 @@ namespace latinime { } closedir(dir); if (remove(dirPath) != 0) { - AKLOGE("Cannot remove directory %s.", dirPath); - return false; + if (maxTries > 0) { + // On NFS, deleting files sometimes creates new files. I'm not sure what the + // correct way of dealing with this is, but for the time being, this seems to work. + removeDirAndFiles(dirPath, maxTries - 1); + } else { + AKLOGE("Cannot remove directory %s.", dirPath); + return false; + } } return true; } diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.h index 3e84a3038..4f1b93a6a 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.h @@ -53,6 +53,8 @@ class FileUtils { private: DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtils); + + static bool removeDirAndFiles(const char *const dirPath, const int maxTries); }; } // namespace latinime #endif /* LATINIME_FILE_UTILS_H */ |