Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7707] IOS :file system-file exists under the resource directory, but exists method returns a false

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionWon't Do
Resolution Date2020-01-09T21:33:53.000+0000
Affected Version/sRelease 1.8.2
Fix Version/sn/a
ComponentsiOS
Labelsqe-ios021312
ReporterSitara Shylaja
AssigneeUnknown
Created2012-02-17T11:24:55.000+0000
Updated2020-01-09T21:33:53.000+0000

Description

description :Test presence of file that exists => false when it should be true steps to reproduce : 1: Install and execute the following code
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 result : Test presence of file that exists => True Actual result : Test presence of file that exists => false note: this occurs is 1.8.1 as well

Comments

  1. Ronald Treur 2012-03-12

    In case there might be any doubt wether this is an actual issue: I have the exact same issue under 1.8.1 and 1.8.2. I didn't check any versions prior to 1.8.1. I spent a few hours fooling around with all other File properties (including the internal ones I noticed being used in the source-code @ Github), but unfortunately didn't get very far.. The File.exists-method seems to return the booleanized (!!) value for 'this._exists', which simply returned 'undefined' in all of my (iOS) test-cases, obviously resulting in 'false' being returned. After looking around for a bit it seems that '_exists' is only set when a file is written to, or is being created. The only other location where this variable is set (to true) is in the File's postscript-method. My guess would be that this method isn't being executed (correctly). For the record: I only have these problems when running the app on my iPhone (iOs 5.0). Running the code in the iPhone Simulator seems to yield the correct results. Titanium Studio, build: 1.0.9.201202141208 Titanium SDK: 1.8.1 & 1.8.2 iPhone 4 with iOs: 5.0 (9A334)
  2. Timan Rebel 2012-03-13

    After some testing with 1.8.2 and iOS 5.1 on an iPhone 4 (Not the simulator) it seems that this problem only occurs in the Resources directory and not in the Application Data directory. {noformat} var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.getResourcesDirectory(), 'app.js'); Ti.API.info('app.js exists: ' + dir.exists()); // Expected true, actual false var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.getResourcesDirectory(), 'testdir/Acl.js'); Ti.API.info('Acl.js exists: ' + dir.exists()); // Expected true, actual false var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.getApplicationDataDirectory()); var dirList = Titanium.Filesystem.getFile(dir.resolve()).getDirectoryListing(); for(var i = 0, length = dirList.length; i < length; i++) { Ti.API.info(i + ': ' + dirList[i] + ', exists: ' + Titanium.Filesystem.getFile(Titanium.Filesystem.getApplicationDataDirectory(), dirList[i]).exists()); // Expected true, actual true } {noformat} Titanium Studio, build: 2.0.0.201203121914 Titanium SDK: 1.8.1 & 1.8.2 iPhone 4 with iOs: 5.1
  3. Alan Hutton 2020-01-09

    It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.

JSON Source