Merge pull request #16062 from minggo/fileutils-issue

fix bug that FileUtils::removeDirectory() can not work on all platforms except iOS and Mac
This commit is contained in:
minggo 2016-07-08 14:54:25 +08:00 committed by GitHub
commit 8d8c295ff0
2 changed files with 4 additions and 15 deletions

View File

@ -1146,24 +1146,12 @@ bool FileUtils::createDirectory(const std::string& path)
bool FileUtils::removeDirectory(const std::string& path)
{
// FIXME: Why using subclassing? an interface probably will be better
// to support different OS
// FileUtils::removeDirectory is subclassed on iOS/tvOS
// and system() is not available on tvOS
#if !defined(CC_PLATFORM_IOS)
if (path.size() > 0 && path[path.size() - 1] != '/')
{
CCLOGERROR("Fail to remove directory, path must terminate with '/': %s", path.c_str());
return false;
}
std::string command = "rm -r ";
// Path may include space.
command += "\"" + path + "\"";
if (system(command.c_str()) >= 0)
return true;
else
#endif
return false;
}

View File

@ -385,8 +385,9 @@ void TestDirectoryFuncs::onEnter()
y = s.height/4;
Label* label = nullptr;
std::string dir = sharedFileUtils->getWritablePath() + "__test/";
std::string dir = sharedFileUtils->getWritablePath() + "__test";
std::string subDir = "dir1/dir2";
std::string fullSubDir = dir + "/" + subDir;
std::string msg;
bool ok;
@ -400,8 +401,8 @@ void TestDirectoryFuncs::onEnter()
this->addChild(label);
// Create sub directories recursively
ok = sharedFileUtils->createDirectory(dir + subDir);
if (ok && sharedFileUtils->isDirectoryExist(dir + subDir))
ok = sharedFileUtils->createDirectory(fullSubDir);
if (ok && sharedFileUtils->isDirectoryExist(fullSubDir))
{
msg = StringUtils::format("createDirectory: Sub directories '%s' created", subDir.c_str());
label = Label::createWithSystemFont(msg, "", 20);