[ 
https://issues.apache.org/jira/browse/CB-4816?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13819039#comment-13819039
 ] 

David Peacock commented on CB-4816:
-----------------------------------

Created pull request for this issue:

https://github.com/apache/cordova-plugin-file/pull/9

> Blackberry File plug-in issues creating files outside sandbox
> -------------------------------------------------------------
>
>                 Key: CB-4816
>                 URL: https://issues.apache.org/jira/browse/CB-4816
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: BlackBerry, Plugin File
>    Affects Versions: 3.0.0
>            Reporter: David Peacock
>            Assignee: Bryan Higgins
>
> I've updated to the latest file plug-in with the automatic un-sandbox changes 
> when requesting a path outside the sandboxed area (these are in the dev 
> branch today).  However there are still some issues with this.  I'm using 
> blackberry.io to get the shared path where I know I should be able to write 
> to.
> I've broken down the process of writing to a file in 5 steps at the bottom of 
> this issue.  First we get the file system, once we have that we get our 
> directory - note we do this because we want to create a sub-folder if it's 
> not already there, getFile does not permit this from what we can tell.  When 
> we get the directory, everything looks ok - we can see the sandbox flag is 
> turned off.  However, in step 3 when we go to get the file we simply pass in 
> the name of the file as we are calling from the directory.  The issue here is 
> when we call getFile with the current logic it thinks it is sandboxed still.  
> If you take a look at the DirectoryEntry.js file for 
> DirectoryEntry.prototype.getFile you will notice it's checking the path 
> parameter alone to determine whether it is sandboxed.  It's not factoring in 
> the currentPath into this equation.  As a result, it goes into the else for 
> sandbox disabled, sets the sandbox state to true, then tries to get the file 
> using currentPath (which is outside the sandbox) as well as the path (file 
> name passed in) and fails.  It shouldn't be going into the else... really the 
> fileUtils.isOutsideSandbox should be checking currentPath + "/" + path in 
> this case.
> I think we need to ensure we are following the API documentation carefully, 
> we need support both relative and absolute paths.  Below are some snippets 
> from the docs:
> getDirectory
> path: The path to the directory to be looked up or created. Either an 
> absolute path, or a relative path from this DirectoryEntry. (DOMString)
> getFile
> path: The path to the file to be looked up or created. Either an absolute 
> path, or a relative path from this DirectoryEntry. (DOMString)
> In my opinion this means the logic in DirectoryEntry.js for getDirectory and 
> getFile should be updated.  The first thing we should do is check to see if 
> the path is absolute, i.e. the first char is "/" - if it is, we shouldn't be 
> using the currentPath here at all I would think?  I made some minor updates 
> to this logic locally and it is working now - at least for how we use it!  I 
> will be making a pull request to GitHub shortly for this.
> Below is a snippet of how we were trying to write to a file:
> //Assuming you have blackberry.io plug-in and cordova file plug-in 
> installed...
> function FileManager() {}
> FileManager.fileDir = blackberry.io.sharedFolder + "/documents/test/"; 
> FileManager.fileName = "test.txt";
> // Step 1 - Get file system
> window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, 
> FileManager.gotWriteFS, null);
> //Step 2 - Get the directory
> FileManager.gotWriteFS = function (fileSystem) {
>    //Get/Create the directory we want to use
>     fileSystem.root.getDirectory(FileManager.fileDir, {
>         create: true,
>         exclusive: false
>     }, FileManager.gotWriteDirEntry, null); };
> //Step 3 - Get the file
> FileManager.gotWriteDirEntry = function (dirEntry) {
>    //Get the file from the current directory
>     dirEntry.getFile(FileManager.fileName, {
>         create: true,
>         exclusive: false
>     }, FileManager.gotWriteFileEntry, null); };
> //Step 4 - Create a writer
> FileManager.gotWriteFileEntry = function (fileEntry) {
>     fileEntry.createWriter(FileManager.gotFileWriter, null); };
> //Step 5 - Write the data
> FileManager.gotFileWriter = function (writer) {
>     writer.write("something to write");
> };



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to