Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27191] Android: Ti.Filesystem.getFile is not tolerant of file: URIs without file:// prefix

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2019-10-15T14:02:30.000+0000
Affected Version/sRelease 8.0.2
Fix Version/sRelease 8.3.0
ComponentsAndroid
Labelsn/a
ReporterChristopher Williams
AssigneeChristopher Williams
Created2019-06-27T14:11:05.000+0000
Updated2019-10-30T14:58:41.000+0000

Description

A URI like this: "file:/data/user/0/com.appcelerator.testApp.testing/cache/_tmp/rmdir1561643019762/myfile.txt" should be valid and supported. However, Android's logic uses some string matching rather than URI parsing to handle the value and it appears to use incorrect logic when the file URI does not have the two trailing slashes before the path.

Comments

  1. Christopher Williams 2019-10-15

    Merged to master, since this was a very specific bug fix needed for the Node compatible fs shim, and I included test cases that exposed and proved the fix.
  2. Samir Mohammed 2019-10-30

    Closing ticket, fix verified in SDK version ` Tested with variations of the test case in: https://github.com/appcelerator/titanium_mobile/pull/11098/files#diff-f9ca2bcf4d55586a8d003e3c0bd51db5. e.g: <code><pre> const appJSURI = isIOS ? 'app.js' : 'app://app.js'; // iOS doesn't support app: uris! const appJS = Ti.Filesystem.getFile(appJSURI); // Generate a file:// URI for the temp dir. Android reports one as-is, iOS reports an sbolute filepath so we pre-pend file:// to it // file:///data/user/0/com.appcelerator.testApp.testing/cache/_tmp on Android // Note also, that IOS reports trailing slash, Android does not const prefix = isIOS ? file://${Ti.Filesystem.tempDirectory} : ${Ti.Filesystem.tempDirectory}/; fileURI = ${prefix}app.js; console.log([1] Copying app.js to ${fileURI}); appJS.copy(fileURI); noSchemeTempAppJS = fileURI.substring(7); // should be /data/user/0/com.appcelerator.testApp.testing/cache/_tmp/app.js console.log([2] Copy's file path should be: ${noSchemeTempAppJS}); const appDataPrivateJS = ${Ti.Filesystem.applicationDataDirectory}/appdata-private.js; appJS.copy(appDataPrivateJS); console.log([3] Copying app.js to ${appDataPrivateJS}`); Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/11098
  3. Samir Mohammed 2019-10-30

    SDK Version ^ 8.3.0.v20191028152746

JSON Source