diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 20648297ba..8d56c85eed 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -1102,17 +1102,28 @@ bool FileUtils::createDirectory(const std::string& path) // Create path recursively subpath = ""; - for (int i = 0; i < dirs.size(); ++i) { + for (int i = 0; i < dirs.size(); ++i) + { subpath += dirs[i]; dir = opendir(subpath.c_str()); + if (!dir) { + // directory doesn't exist, should create a new one + int ret = mkdir(subpath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); if (ret != 0 && (errno != EEXIST)) { + // current directory can not be created, sub directories can not be created too + // should return return false; } } + else + { + // directory exists, should close opened dir + closedir(dir); + } } return true; #endif @@ -1122,8 +1133,9 @@ bool FileUtils::createDirectory(const std::string& path) static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { auto ret = remove(fpath); - if (ret) { - log("Fail to remove:%s ",fpath); + if (ret) + { + log("Fail to remove: %s ",fpath); } return ret;