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-13 08:33:57 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2013-12-13 08:33:57 -0800
commit3ac00d1889f7752bec6a653842a1fc2f079ab911 (patch)
treefc8c92ee41a00075830a6363bfeafe85aa8cbc0b /native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
parent379a7e88efaff2af42313faddac86fbdfb5881d1 (diff)
parenta245d15da5d295af21ead9a01583c64796a31ad7 (diff)
downloadlatinime-3ac00d1889f7752bec6a653842a1fc2f079ab911.tar.gz
latinime-3ac00d1889f7752bec6a653842a1fc2f079ab911.tar.xz
latinime-3ac00d1889f7752bec6a653842a1fc2f079ab911.zip
am a245d15d: Have dicttool use the native library to generate v4 dicts.
* commit 'a245d15da5d295af21ead9a01583c64796a31ad7': Have dicttool use the native library to generate v4 dicts.
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;
}