[TIMOB-27191] Android: Ti.Filesystem.getFile is not tolerant of file: URIs without file:// prefix
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-10-15T14:02:30.000+0000 |
Affected Version/s | Release 8.0.2 |
Fix Version/s | Release 8.3.0 |
Components | Android |
Labels | n/a |
Reporter | Christopher Williams |
Assignee | Christopher Williams |
Created | 2019-06-27T14:11:05.000+0000 |
Updated | 2019-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.
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.
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/11098SDK Version ^ 8.3.0.v20191028152746