Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4469] Android: Filesystem exists() method used on file in resourcesDirectory always returns true even if the file is not present

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-01-04T13:51:59.000+0000
Affected Version/sRelease 1.7.0
Fix Version/sSprint 2011-37, Release 1.8.0
ComponentsAndroid
Labelsmodule_filesystem, qe-testadded
ReporterAnirudh Nagesh
AssigneeAllen Yeung
Created2011-06-21T12:42:12.000+0000
Updated2013-11-13T12:35:59.000+0000

Description

Note: please see [this comment|#comment-164088] below for clearer testcase and accurate explanation of the bug. 1. create an empty mobile project. 2. Copy the following sample code. http://pastie.org/2102937 3. The image is not loaded even if it is present in the filesystem. Works fine with Ti SDK 1.6.2

Comments

  1. Don Thorp 2011-06-22

    Please move the example code from pastie to the actual ticket. Also, does it fail if you don't put the @ in the name.
  2. Anirudh Nagesh 2011-06-22

    the code snippet can be found below.
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
       
       // create tab group
       
       function find(path) 
       {
       
                 if (Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'KS_nav_ui@A.png').exists()) 
                 {
               path = 'KS_nav_ui@A.png';
               
                 }
       
           return path;
       }
       //
       // create base UI tab and root window
       //
       var win1 = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff',
           backgroundImage:find('KS_nav_ui.png')
       });
       
       alert(win1.backgroundImage);
       win1.open();
       
    2. No, it does not fail if '@' is not in the name.
  3. Anirudh Nagesh 2011-06-22

    sending back to dev with required info.
  4. Thomas Huelbert 2011-06-27

    kicking back so Don can see it
  5. Don Thorp 2011-06-27

    Will look into why it's returning true. It should not.
  6. Don Thorp 2011-07-20

    Attaching code where I added more logging statements. I could not get this to fail. It is not always returning true.
       
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
       
       function find(path) {
       
       	Ti.API.debug("Path with @ exists: " + Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'KS_nav_ui@A.png').exists());
       	Ti.API.debug("Path w/o @ exists: " +  Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'KS_nav_ui.png').exists());
       
       	if (Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'KS_nav_ui@A.png').exists()) {
       		path = 'KS_nav_ui@A.png';	
       	}
       
       	return path;
       }
       //
       // create base UI tab and root window
       //
       var win1 = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff',
           backgroundImage:find('KS_nav_ui.png')
       });
       
       alert(win1.backgroundImage);
       win1.open();
       
  7. Anirudh Nagesh 2011-07-20

    Don, I can still reproduce the issue with 1.7.0! I double checked it with both 1.6.2 and 1.7.0 In 1.6.2, 'exists()' returns false and true properly when the file is not present in the resources directory. In 1.7.0, it always returns true. Please let me know if you need any further information.
  8. Paul Dowsett 2011-08-25

    This has been reported again in TC-211. Note that this issue specifically occurs for testing the existence of files in resourcesDirectory. Other locations, such as applicationDataDirectory, are not affected. Environment Information: * Titanium SDK version: 1.7.2.97c3689. * Platform & version: Android 2.1.1 and Android 2.3.3 * Device Details: Android 2.1.1 and Android 2.3.3 * Host Operating System: OSX 10.7 (Lion) * Titanium Studio version: Titanium Studio, build: 1.0.2.201107130739 The user has observed this problem using the following Titanium SDKs: * 1.7.1 - No bug * 1.7.2 - Bug exists * 1.7.3 - Bug exists I have also verified that the issue still exists in 1.7.3. The user has provided a simpler testcase as follows:
       var resourcesFileDoesExist = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'app.js');
       var resourcesFileDoesNotExist = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'this-file-does-not-exist.js');
       
       var newFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'this-file-exists.js');
       newFile.write("testing a file");
       
       var appDataFileDoesExist = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'this-file-exists.js');
       var appDataFileDoesNotExist = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'this-file-does-not-exist.js');
       
       var label = Ti.UI.createLabel({
         color: '#FFF'
       });
       label.text = '*** Resources Dir: \nTest presence of file that exists => ' +
         resourcesFileDoesExist.exists() +
         '\nTest presence of file that does not exist => ' +
         resourcesFileDoesNotExist.exists() +
         '\n\n*** appData Dir: \nTest presence of file that exists => ' +
         appDataFileDoesExist.exists() +
         '\nTest presence of file that does not exist => ' +
         appDataFileDoesNotExist.exists();
       
       var win = Ti.UI.createWindow({
         backgroundColor: '#000'
       });
       win.add(label);
       win.open();
       
    Expected Results:
       *** Resources Dir:
       True
       False
       *** appData Dir:
       True
       False
       
    Actual Results:
       *** Resources Dir:
       True
       True
       *** appData Dir:
       True
       False
       
  9. Jon Alter 2011-09-01

    folder.exists()

    Description

    exists() returns "false" when pointing to a folder that exists and "true" when the folder does not exist

    Steps to reproduce

    Step 1: create a new app Step 2: run the code below Step 3: click the window Step 4: look in the console Step 5: notice that there is no "data" directory but exists returns "true" Step 6: create a "data" directory in Resources, and create a couple files inside it Step 7: make a small change to tiapp.xml, delete the change, and save the file so that fastdev will pull in your new folder Step 8: run the app Step 9: click the window Step 10: notice that there is now a "data" directory but exists returns "false" Step 11: notice that getDirectoryListing listed the contents of your data directory, proving that the folder is indeed there

    Repro Case

       var win = Ti.UI.createWindow({
         backgroundColor:"#fff"
       });
       win.open();
       
       win.addEventListener('click', function(e){
       	var srcDataDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "data");
         	Ti.API.info('SRC EXISTS = ' + srcDataDir.exists());
       	Ti.API.info('SRC LISTING = ' + srcDataDir.getDirectoryListing());
       });
       

    Environment

    TiSDK 1.7.2 Android Emulator 2.2

    Associated Helpdesk Ticket

    http://appc.me/c/APP-728922
  10. Marshall Culpepper 2011-09-15

    We need to make sure to test the fix for this with Fastdev automatic changes, it looks like the current changeset disables it completely. The test is pretty simple: * Run the project from TiStudio on the emulator (Fastdev should be automatically started) * After the app starts, change some JS code directly in TiStudio * Re-run the app (it should restart almost immediately, and have the changes you just made -- coming from FastDev mode)
  11. Michael Pettiford 2011-12-09

    Tested on Ti Studio 1.0.7.201112080131 
Ti Mob SDK 1.8.0.1.v20111209011840 
OSX Lion Nexus S OS 2.3.6, Android emulator with fast dev mode on Expected filesystem behavior is shown
  12. Michael Pettiford 2012-01-04

    Reopening/closing to add/remove labels

JSON Source