Android - system.pathForFile - bugged implementation?

Hi!

I read current description of system.pathForFile here:

http://docs.coronalabs.com/api/library/system/pathForFile.html

Here is what function system.pathForFile should return:

If the base directory is system.ResourceDirectory and the generated path points to a non-existent file, nil is returned and a warning message is displayed in the Terminal/console.

I know about “Android File Restrictions” but I think that this is not applicable here.

I unit test my code and I found something strange about this function. Test it yourself if you have android device:

  1. Create new blank project in Corona SDK simulator.

  2. In main.lua file paste this code:

 print(“Test started!”);
local path = system.pathForFile( “notExistingFile.txt” )
if path ~= nil then print(“First run : path is “…path…” !”); else print(“First run : path is null!”); end
local path2 = system.pathForFile( “notExistingFile.txt” )
if path2 ~= nil then print(“Second run : path2 is “…path2…” !”); else print(“Second run : path2 is null!”); end
print(“Test ended!”);

Now if you run this code in Simulator, result is as expected:

Copyright © 2009-2013  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2013.2100
Test started!
WARNING: Cannot create path for resource file ‘notExistingFile.txt’ b/c it does
not exist.

First run : path is null!
WARNING: Cannot create path for resource file ‘notExistingFile.txt’ b/c it does
not exist.

Second run : path2 is null!
Test ended!

  1. Generate android app and load it on android device, then run application. Result is strange:

V/Corona  (29095): > Class.forName: network.LuaLoader
V/Corona  (29095): < Class.forName: network.LuaLoader
V/Corona  (29095): Loading via reflection: network.LuaLoader
I/Corona  (29095): Test started!
I/Corona  (29095): First run : path is null!
I/Corona  (29095): Second run : path2 is /data/data/com.gmail.mymail.ABC/files/
coronaResources/notExistingFile.txt !
I/Corona  (29095): Test ended!

  1. If I leave app and return to app, result is even worse:

V/Corona  (29095): > Class.forName: network.LuaLoader
V/Corona  (29095): < Class.forName: network.LuaLoader
V/Corona  (29095): Loading via reflection: network.LuaLoader
I/Corona  (29095): Test started!
I/Corona  (29095): First run : path is /data/data/com.gmail.mymail.ABC/files/co
ronaResources/notExistingFile.txt !
I/Corona  (29095): Second run : path2 is /data/data/com.gmail.mymail.ABC/files/
coronaResources/notExistingFile.txt !
I/Corona  (29095): Test ended!

My point is that this behavior is not as described in first quote.

My telephone with android is HTC One. Android version: 4.2.2.

I would like to ask for two things:

  1. Can anyone test code which I posted above with other Android devices? Please attach debug log which can be captured on PC with command: adb.exe logcat Corona:v *:s

  2. If problem is confirmed what should I do then? Rise bug report? What to do if this problem is only with my device?

Thank you in advance for your help.

Btw: Limited quotes number is … not very smart idea.

Regards,

Ikeban

This is potentially a bug, but it’s also not one that I think is a real issues.

On Android, the system.ResourceDirectory is the .APK file which is nothing more than a .zip file.  Corona SDK automatically extracts files needed by the SDKs display objects automatically.  Some files are extracted when you try to access them with system.pathForFile().

What I think may be happening (which may be a bug) is that we are extracting a blank file as part of that attempt. This would explain why you get the nil the first time, but not on subsequent calls.

But why this shouldn’t be an issue is you should know what all is in your resource bundle. You can’t add files there or remove them. There isn’t much of a reason to check for the existence of files in your bundle.  Now for files in system.DocumentsDirectory, .CachesDirectory or .TemporaryDirectory, your app may not know the state of those files and it’s important to know if the file/directory exists or not.

But I suppose that we probably should not be extracting a blank file (if that’s the case), so feel free to submit a bug report using the link above.  Please make sure to include a config.lua and build.settings file so we don’t have to guess at your settings.

Thanks

Rob

Rob

Hi Rob,

Thank you for your fast answer!

As you suggested I will rise bug report with all required information and with lowest priority possible, since this is not really big problem. From your description I now understand why I observe such behavior, but during development it is nice to have opportunity to locate missing files from resource bundle (it is quite common :stuck_out_tongue: ). Currently missing files are detected only first time, so it can result in very hard to find bug.

Have a nice day,
Ikeban

This is potentially a bug, but it’s also not one that I think is a real issues.

On Android, the system.ResourceDirectory is the .APK file which is nothing more than a .zip file.  Corona SDK automatically extracts files needed by the SDKs display objects automatically.  Some files are extracted when you try to access them with system.pathForFile().

What I think may be happening (which may be a bug) is that we are extracting a blank file as part of that attempt. This would explain why you get the nil the first time, but not on subsequent calls.

But why this shouldn’t be an issue is you should know what all is in your resource bundle. You can’t add files there or remove them. There isn’t much of a reason to check for the existence of files in your bundle.  Now for files in system.DocumentsDirectory, .CachesDirectory or .TemporaryDirectory, your app may not know the state of those files and it’s important to know if the file/directory exists or not.

But I suppose that we probably should not be extracting a blank file (if that’s the case), so feel free to submit a bug report using the link above.  Please make sure to include a config.lua and build.settings file so we don’t have to guess at your settings.

Thanks

Rob

Rob

Hi Rob,

Thank you for your fast answer!

As you suggested I will rise bug report with all required information and with lowest priority possible, since this is not really big problem. From your description I now understand why I observe such behavior, but during development it is nice to have opportunity to locate missing files from resource bundle (it is quite common :stuck_out_tongue: ). Currently missing files are detected only first time, so it can result in very hard to find bug.

Have a nice day,
Ikeban