New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUtils::removeFile doesn't work iOS #8568

Closed
ahlwong opened this Issue Oct 6, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@ahlwong
Contributor

ahlwong commented Oct 6, 2014

In Cocos2d-x 3.3beta0

The FileUtils::removeFile doesn't seem to work. It generates the correct command but it doesn't seem to do anything. Perhaps it has to do with this Stack Overflow post? http://stackoverflow.com/questions/11291164/system-command-not-working-when-enabling-app-sandboxing

"rm -f "/Users/my_user/Library/Developer/CoreSimulator/Devices/2821C4FC-9316-4183-A3A9-62E19BAE4A65/data/Containers/Data/Application/FEDDBD50-526B-4C88-A58B-816190CE6A47/Documents/db.sqlite""

@minggo minggo added this to the v3.3 milestone Oct 8, 2014

@minggo

This comment has been minimized.

Show comment
Hide comment
@minggo

minggo Oct 8, 2014

Contributor

@Dhilan007
Could you please take a look?

Contributor

minggo commented Oct 8, 2014

@Dhilan007
Could you please take a look?

@WenhaiLin

This comment has been minimized.

Show comment
Hide comment
@WenhaiLin

WenhaiLin Oct 9, 2014

Contributor

@ahlwong I test it on IOS7.1 Simulator,it's work normal.I think you passes the wrong path.["...db.sqlite"]

Contributor

WenhaiLin commented Oct 9, 2014

@ahlwong I test it on IOS7.1 Simulator,it's work normal.I think you passes the wrong path.["...db.sqlite"]

@ahlwong

This comment has been minimized.

Show comment
Hide comment
@ahlwong

ahlwong Oct 9, 2014

Contributor

@Dhilan007 I just tested it again and it's not working in the simulator or on my devices. It is working on Android. Here are some more details:

iOS 8 - iPhone 6 simulator - Xcode 6.0.1
rm -f "/Users/my_user/Library/Developer/CoreSimulator/Devices/2821C4FC-9316-4183-A3A9-62E19BAE4A65/data/Containers/Data/Application/173CEBC8-04B3-47EA-BD90-A8E646220CD4/Documents/db.sqlite"

iOS 7.1.2 - iPhone 5 device - Xcode 6.0.1
cocos2d: rm -f "/var/mobile/Applications/348EC781-C8C3-49B0-BF12-523B0EA7FA63/Documents/db.sqlite"

Android 4.4.2 Device
10-09 11:15:10.538: D/cocos2d-x debug info(5910): rm -f "/data/data/com.my.app/files/db.sqlite"
10-09 11:15:10.568: D/CCFileUtils-android.cpp(5910): relative path = database/db.sqlite

I'm creating the path like so:
FileUtils::getInstance()->getWritablePath() + "db.sqlite"

My copyFile code and reading the file works so the path should be correct. Also, the removeFile is still returning true even when the file sin't deleted.

Contributor

ahlwong commented Oct 9, 2014

@Dhilan007 I just tested it again and it's not working in the simulator or on my devices. It is working on Android. Here are some more details:

iOS 8 - iPhone 6 simulator - Xcode 6.0.1
rm -f "/Users/my_user/Library/Developer/CoreSimulator/Devices/2821C4FC-9316-4183-A3A9-62E19BAE4A65/data/Containers/Data/Application/173CEBC8-04B3-47EA-BD90-A8E646220CD4/Documents/db.sqlite"

iOS 7.1.2 - iPhone 5 device - Xcode 6.0.1
cocos2d: rm -f "/var/mobile/Applications/348EC781-C8C3-49B0-BF12-523B0EA7FA63/Documents/db.sqlite"

Android 4.4.2 Device
10-09 11:15:10.538: D/cocos2d-x debug info(5910): rm -f "/data/data/com.my.app/files/db.sqlite"
10-09 11:15:10.568: D/CCFileUtils-android.cpp(5910): relative path = database/db.sqlite

I'm creating the path like so:
FileUtils::getInstance()->getWritablePath() + "db.sqlite"

My copyFile code and reading the file works so the path should be correct. Also, the removeFile is still returning true even when the file sin't deleted.

@ahlwong

This comment has been minimized.

Show comment
Hide comment
@ahlwong

ahlwong Oct 9, 2014

Contributor

@Dhilan007 The exit code I'm seeing on iOS is 5 whereas in Android it is 0. The code that checks the exit code is:

if (system(command.c_str()) >= 0) // an exit code > 0 means an error occurred

it should be:

if (system(command.c_str()) == 0) // exit(0) means success

The same check is used for removeDirectory, it should also be fixed at least for systems running on unix or linux.

I'm still unsure why the command is not succeeding on iOS for me. For now, I've changed the code to use std::remove, which works on iOS, simulator and Android

bool FileUtils::removeFile(const std::string &path)
{
// Remove downloaded file
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
if (remove(path.c_str()) == 0)
return true;
else
return false;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
if (DeleteFileA(path.c_str()))
{
return true;
}
return false;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
std::string command = "cmd /c del /q ";
std::string win32path = path;
int len = win32path.length();
for (int i = 0; i < len; ++i)
{
if (win32path[i] == '/')
{
win32path[i] = '';
}
}
command += win32path;

if (WinExec(command.c_str(), SW_HIDE) > 31)
    return true;
else
    return false;

#endif
}

Contributor

ahlwong commented Oct 9, 2014

@Dhilan007 The exit code I'm seeing on iOS is 5 whereas in Android it is 0. The code that checks the exit code is:

if (system(command.c_str()) >= 0) // an exit code > 0 means an error occurred

it should be:

if (system(command.c_str()) == 0) // exit(0) means success

The same check is used for removeDirectory, it should also be fixed at least for systems running on unix or linux.

I'm still unsure why the command is not succeeding on iOS for me. For now, I've changed the code to use std::remove, which works on iOS, simulator and Android

bool FileUtils::removeFile(const std::string &path)
{
// Remove downloaded file
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
if (remove(path.c_str()) == 0)
return true;
else
return false;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
if (DeleteFileA(path.c_str()))
{
return true;
}
return false;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
std::string command = "cmd /c del /q ";
std::string win32path = path;
int len = win32path.length();
for (int i = 0; i < len; ++i)
{
if (win32path[i] == '/')
{
win32path[i] = '';
}
}
command += win32path;

if (WinExec(command.c_str(), SW_HIDE) > 31)
    return true;
else
    return false;

#endif
}

@ahlwong ahlwong changed the title from FileUtils::removeFile doesn't work OSX, Xcode Simulator to FileUtils::removeFile doesn't work iOS Oct 9, 2014

@WenhaiLin

This comment has been minimized.

Show comment
Hide comment
@WenhaiLin

WenhaiLin Oct 10, 2014

Contributor

@ahlwong Thanks very much.I fixed this issue at #8608

Contributor

WenhaiLin commented Oct 10, 2014

@ahlwong Thanks very much.I fixed this issue at #8608

@minggo minggo closed this Oct 10, 2014

minggo added a commit that referenced this issue Oct 10, 2014

Merge pull request #8608 from Dhilan007/v3-fileutil-ios
issue #8568: Fixed FileUtils::removeFile doesn't work on iOS

cocos-travis-mac added a commit to cocos-travis-mac/cocos2d-x that referenced this issue Oct 10, 2014

Merge pull request #8608 from Dhilan007/v3-fileutil-ios
issue #8568: Fixed FileUtils::removeFile doesn't work on iOS

WenhaiLin added a commit to WenhaiLin/cocos2d-x that referenced this issue Oct 10, 2014

Squashed commit of the following:
commit 4541150
Merge: b508804 a576198
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Fri Oct 10 16:41:47 2014 +0800

    Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3-win32-warn

commit a576198
Merge: d5658a6 53cde3f
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 16:40:56 2014 +0800

    Merge pull request #8624 from CocosRobot/update_lua_bindings_1412930259

    [AUTO]: updating luabinding automatically

commit 53cde3f
Author: CocosRobot <redmine@cocos2d-x.org>
Date:   Fri Oct 10 08:39:46 2014 +0000

    [AUTO]: updating luabinding automatically

commit b508804
Merge: 83150aa d5658a6
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Fri Oct 10 16:38:11 2014 +0800

    Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3-win32-warn

    Conflicts:
    	tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp

commit d5658a6
Merge: 985b2a7 72ebd71
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 16:31:01 2014 +0800

    Merge pull request #8621 from natural-law/v3

    Update the reference of submodule cocos2d-console.

commit 985b2a7
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 16:30:26 2014 +0800

    [ci skip] Update CHANGELOG

commit 63e4d7c
Merge: 00f8f84 2013cdb
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 16:28:21 2014 +0800

    Merge pull request #8614 from andyque/fixEditBoxMaxLengthOnMac

    fix setMaxLength issue of EditBox-mac

commit 72ebd71
Author: zhangbin <zhangbin@cocos2d-x.org>
Date:   Fri Oct 10 16:28:03 2014 +0800

    Update the reference of submodule cocos2d-console.

commit 00f8f84
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:56:15 2014 +0800

    [ci skip] Update CHANGELOG

commit 4b7d569
Merge: c774867 6f50143
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:52:50 2014 +0800

    Merge pull request #8573 from Dhilan007/v3-labelatlas

    fix #8569: LabelAtlas opacity do not change when setting parent node's opacity

commit c774867
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:37:08 2014 +0800

    [ci skip] Update CHANGELOG

commit 44f3dcd
Merge: a11091a 7fb448e
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:35:43 2014 +0800

    Merge pull request #8608 from Dhilan007/v3-fileutil-ios

    issue #8568: Fixed FileUtils::removeFile doesn't work on iOS

commit a11091a
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:30:30 2014 +0800

    [ci skip] Update CHANGELOG

commit 7d4a235
Merge: 8964c88 a08d0e4
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:28:23 2014 +0800

    Merge pull request #8611 from dabingnn/v3_fixGLProgramCrash

    V3 fix gl program crash

commit 8964c88
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:27:12 2014 +0800

    [ci skip] Update CHANGELOG

commit 2013cdb
Author: andyque <guanghui8827@126.com>
Date:   Fri Oct 10 15:26:33 2014 +0800

    fix setMaxLength issue of EditBox-mac

commit 01e3ae2
Merge: 49b3e90 da48649
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:23:25 2014 +0800

    Merge pull request #8606 from andyque/fixButtonContentSize

    fix button title only content size issue

commit 49b3e90
Merge: df60fde f97a7ae
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:22:17 2014 +0800

    Merge pull request #8604 from samuele3hu/v3_3D

    Add CameraTest、OBBTest and related lua bindings

commit 7fb448e
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Fri Oct 10 15:13:05 2014 +0800

    add 'static' for global function

commit df60fde
Merge: 4856b67 d5fe075
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:05:39 2014 +0800

    Merge pull request #8610 from andyque/fixCocostudioIncludePath

    fix cocostudio include path

commit a08d0e4
Merge: e69465e 2a95286
Author: Huabing.Xu <dabingnn@gmail.com>
Date:   Fri Oct 10 15:05:09 2014 +0800

    Merge branch 'v3' into v3_fixGLProgramCrash

commit 4856b67
Merge: 2a95286 e9e9741
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 15:00:28 2014 +0800

    Merge pull request #7979 from giginet/scene-reader-canvas-size

    SceneReader sets contentSize by canvasSize.

commit e69465e
Author: Huabing.Xu <dabingnn@gmail.com>
Date:   Fri Oct 10 14:06:37 2014 +0800

    remove texture unit 4-7, only 0 -3 is reserved

commit f097c76
Author: Huabing.Xu <dabingnn@gmail.com>
Date:   Fri Oct 10 14:05:57 2014 +0800

    fix compile error for macro redefinition

commit 250875b
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Fri Oct 10 14:03:20 2014 +0800

    fixed compile error

commit d5fe075
Author: andyque <guanghui8827@126.com>
Date:   Fri Oct 10 13:48:49 2014 +0800

    fix cocostudio include path

commit 6a8c4f4
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Fri Oct 10 11:59:35 2014 +0800

    Fixed FileUtils::removeFile doesn't work on iOS

commit 2a95286
Merge: ba5ff2e 5b620fb
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 11:13:41 2014 +0800

    Merge pull request #7785 from DaisukeHashimoto/fix_CCActionManagerEx_Bug

    use fileName for _actionDic key

commit da48649
Author: andyque <guanghui8827@126.com>
Date:   Fri Oct 10 11:01:51 2014 +0800

    fix button title only content size issue

commit ba5ff2e
Merge: 3aa6337 7a23cc3
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 10:46:24 2014 +0800

    Merge pull request #8586 from super626/v3

    Fix warning of Bundle3D and modify light

commit 3aa6337
Merge: d7d52a7 d5e29d2
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 10:41:52 2014 +0800

    Merge pull request #8599 from dabingnn/v3_fixEGLConfigOnAndroid

    fix egl config error on android

commit d7d52a7
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 10:19:07 2014 +0800

    [ci skip] Update CHANGELOG

commit 254ee5b
Merge: d5e29d2 f928046
Author: Huabing.Xu <dabingnn@gmail.com>
Date:   Fri Oct 10 10:09:26 2014 +0800

    Merge branch 'v3' into v3_fixGLProgramCrash

commit cbc2a52
Merge: af4a197 5027f24
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 10:08:22 2014 +0800

    Merge pull request #8603 from ahlwong/v3

    Fix UIButton Scale 9 Highlight

commit af4a197
Merge: f928046 a5a16ee
Author: minggo <ming@cocos2d-x.org>
Date:   Fri Oct 10 10:02:05 2014 +0800

    Merge pull request #8602 from fengl2/patch-1

    the android library path in proj.andriod/project.properties file is wrong

commit 7a23cc3
Merge: 1ef511d b77559f
Author: yangxiao <yangxiao@cocos2d-x.org>
Date:   Fri Oct 10 09:55:56 2014 +0800

    Merge branch 'v3' of https://github.com/super626/cocos2d-x into v3

commit 1ef511d
Merge: 88fc425 f928046
Author: yangxiao <yangxiao@cocos2d-x.org>
Date:   Fri Oct 10 09:53:57 2014 +0800

    Merge branch 'newcode' into v3

commit f97a7ae
Merge: 115d815 f928046
Author: samuele3hu <qingkui.hu@cocos2d-x.org>
Date:   Fri Oct 10 09:52:29 2014 +0800

    Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3_3D

commit 115d815
Author: samuele3hu <qingkui.hu@cocos2d-x.org>
Date:   Fri Oct 10 09:49:25 2014 +0800

    Add CameraTest、OBBTest and related lua bindings

commit 5027f24
Author: Ahlwong <alexanderhlwong@gmail.com>
Date:   Thu Oct 9 12:48:09 2014 -0700

    Fix UIButton Scale 9 Highlight

commit a5a16ee
Author: NeoLeeee <lifengdmu@gmail.com>
Date:   Fri Oct 10 01:33:41 2014 +0800

    the android library path is wrong

    if you run the following command in your game forder

    cocos run -p android

    it will give you the following error since the path is wrong

    BUILD FAILED
    /Users/lifeng/dev/adt_bundle_mac/sdk/tools/ant/build.xml:459: ../../../cocos/platform/android/java resolve to a path with no project.properties file for project /Users/lifeng/study/cosco2dx/MyFirstGame/proj.android

commit d5e29d2
Author: Huabing.Xu <dabingnn@gmail.com>
Date:   Thu Oct 9 18:34:14 2014 +0800

    fix gel Config error on android

commit b77559f
Merge: 88fc425 34efbf1
Author: XiaoYang <yangxiao@cocos2d-x.org>
Date:   Thu Oct 9 18:31:24 2014 +0800

    Merge pull request #136 from songchengjiang/new_v3

    Fixed CosOuterAngle error

commit 83150aa
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Thu Oct 9 17:19:43 2014 +0800

    fix warns and memory leak

commit f928046
Merge: db72756 8ea473d
Author: minggo <ming@cocos2d-x.org>
Date:   Thu Oct 9 17:05:39 2014 +0800

    Merge pull request #8580 from Dhilan007/v3-labelfix

    issue #8492:fix endless loop when dimensions that are not enough to fit one character

commit 88fc425
Merge: 222bf57 7ecd8c5
Author: yangxiao <yangxiao@cocos2d-x.org>
Date:   Thu Oct 9 17:02:10 2014 +0800

    Merge branch 'v3' of https://github.com/super626/cocos2d-x into v3

commit 222bf57
Merge: c087f31 db72756
Author: yangxiao <yangxiao@cocos2d-x.org>
Date:   Thu Oct 9 17:01:35 2014 +0800

    Merge branch 'newcode' into v3

commit 34efbf1
Author: songchengjiang <songcheng.jiang@chukong-inc.com>
Date:   Thu Oct 9 16:16:02 2014 +0800

    Fixed getCosOuterAngle errors

commit 88012cf
Merge: 9ba70ec 7ecd8c5
Author: songchengjiang <songcheng.jiang@chukong-inc.com>
Date:   Thu Oct 9 15:49:50 2014 +0800

    Merge branch 'v3_new' into v3

    Conflicts:
    	tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua

commit 7ecd8c5
Merge: c087f31 cba155b
Author: XiaoYang <yangxiao@cocos2d-x.org>
Date:   Thu Oct 9 10:14:06 2014 +0800

    Merge pull request #135 from lvlonggame/v3

    Remove string err that is no used

commit c087f31
Author: yangxiao <yangxiao@cocos2d-x.org>
Date:   Thu Oct 9 10:12:52 2014 +0800

    modify return type of getDirection and getDirectionInWorld

commit 6f50143
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Wed Oct 8 18:28:24 2014 +0800

    Fixed LabelAtlas opacity do not change when setting parent node's opacity

commit 8ea473d
Author: Dhilan007 <wenhai.lin@chukong-inc.com>
Date:   Wed Oct 8 18:22:35 2014 +0800

    fix endless loop when dimensions that are not enough to fit one character

commit cba155b
Author: lvlong <lvlong@chukong-inc.com>
Date:   Wed Oct 8 15:23:31 2014 +0800

    Remove string err no used

commit 9ba70ec
Author: songchengjiang <songcheng.jiang@chukong-inc.com>
Date:   Mon Sep 29 16:57:45 2014 +0800

    Sprite3DHitTest use BoundingBox

commit a2a5234
Author: songchengjiang <songcheng.jiang@chukong-inc.com>
Date:   Mon Sep 29 11:43:52 2014 +0800

    Finished Sprite3DHitTest

commit 3b7dd19
Author: songchengjiang <songcheng.jiang@chukong-inc.com>
Date:   Sun Sep 28 18:05:09 2014 +0800

    Add Sprite3DHitTest

commit ca4fa42
Author: songchengjiang <songcheng.jiang@chukong-inc.com>
Date:   Sun Sep 28 17:01:43 2014 +0800

    Sprite3DTest.lua:
    Add Sprite3DWithSkinTest
    Add AttachmentTest
    Add Sprite3DReskinTest
    Add Sprite3DMirrorTest

commit e9e9741
Author: giginet <giginet.net@gmail.com>
Date:   Tue Sep 9 22:30:52 2014 +0900

    SceneReader sets contentSize by canvasSize.

    We could not get the canvas size of the scene which created on CocosStudio.

    Thanks to this commit, we can get scene's canvas size by Node::getContentSize()

    ```cpp
    auto scene = cocos2d::cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("Scene.json");
    int width = scene->getContentSize().width;
    int height = scene->getContentSize().height;
    cocos2d::log("canvasSize = %d, %d", width, height);
    ```

commit 5b620fb
Author: Daisuke Hashimoto <dsk.hashimoto@gmail.com>
Date:   Thu Aug 14 21:10:51 2014 +0900

    use fileName for _actionDic key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment