aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-12 15:08:10 +0900
committerJean Chalard <jchalard@google.com>2013-12-13 18:18:20 +0900
commita245d15da5d295af21ead9a01583c64796a31ad7 (patch)
tree1156247b156533c7b946f0f42c1d74642ea991e1 /native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
parentaf0c222a5ec4a8dda3db7b99b2e641434f2c4225 (diff)
downloadlatinime-a245d15da5d295af21ead9a01583c64796a31ad7.tar.gz
latinime-a245d15da5d295af21ead9a01583c64796a31ad7.tar.xz
latinime-a245d15da5d295af21ead9a01583c64796a31ad7.zip
Have dicttool use the native library to generate v4 dicts.
Yay ! Change-Id: Iea8ced9e81031b9ab7eff05ad9ef7215be248de9
Diffstat (limited to 'native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp')
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp17
1 files changed, 14 insertions, 3 deletions
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;
}