Return-Path: X-Original-To: apmail-cordova-issues-archive@minotaur.apache.org Delivered-To: apmail-cordova-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 638A91983A for ; Fri, 18 Mar 2016 00:44:36 +0000 (UTC) Received: (qmail 17052 invoked by uid 500); 18 Mar 2016 00:44:34 -0000 Delivered-To: apmail-cordova-issues-archive@cordova.apache.org Received: (qmail 16983 invoked by uid 500); 18 Mar 2016 00:44:34 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 16553 invoked by uid 99); 18 Mar 2016 00:44:33 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Mar 2016 00:44:33 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id A87CB2C1F54 for ; Fri, 18 Mar 2016 00:44:33 +0000 (UTC) Date: Fri, 18 Mar 2016 00:44:33 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CB-10798) Cannot create folder into cordova.file.externalRootDirectory on Android 6.x Marshmallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-10798?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15200718#comment-15200718 ] ASF GitHub Bot commented on CB-10798: ------------------------------------- Github user dblotsky commented on a diff in the pull request: https://github.com/apache/cordova-plugin-file/pull/170#discussion_r56600287 --- Diff: src/android/FileUtils.java --- @@ -433,28 +434,41 @@ public void run(JSONArray args) throws JSONException, IOException { else if (action.equals("getDirectory")) { threadhelper( new FileOp( ){ public void run(JSONArray args) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { - String dirname=args.getString(0); - String path=args.getString(1); - JSONObject obj = getFile(dirname, path, args.optJSONObject(2), true); - callbackContext.success(obj); + String dirname = args.getString(0); + String path = args.getString(1); + String nativeURL = resolveLocalFileSystemURI(dirname).getString("nativeURL"); + boolean containsCreate = args.toString().contains("\"create\":true"); + + if(containsCreate && needPermission(nativeURL, WRITE)) { + getPermissionDir(WRITE); + } + else if(!containsCreate && needPermission(nativeURL, READ)) { + getPermissionDir(READ); + } + else { + JSONObject obj = getFile(dirname, path, args.optJSONObject(2), true); + callbackContext.success(obj); + } } }, rawArgs, callbackContext); } else if (action.equals("getFile")) { threadhelper( new FileOp( ){ public void run(JSONArray args) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { - String dirname=args.getString(0); - /* - * If we don't have the package name in the path, we're reading and writing to places we need permission for - */ - if(dirname.contains(cordova.getActivity().getPackageName()) || - hasReadPermission()) { - String path = args.getString(1); - JSONObject obj = getFile(dirname, path, args.optJSONObject(2), false); - callbackContext.success(obj); + String dirname = args.getString(0); + String path = args.getString(1); + String nativeURL = resolveLocalFileSystemURI(dirname).getString("nativeURL"); + boolean containsCreate = args.toString().contains("\"create\":true"); + + if(containsCreate && needPermission(nativeURL, WRITE)) { + getPermissionFile(WRITE); + } + else if(!containsCreate && needPermission(nativeURL, READ)) { + getPermissionFile(READ); --- End diff -- This code is similar to the `WRITE` case, so it might be better to factor out them both into a function. > Cannot create folder into cordova.file.externalRootDirectory on Android 6.x Marshmallow > --------------------------------------------------------------------------------------- > > Key: CB-10798 > URL: https://issues.apache.org/jira/browse/CB-10798 > Project: Apache Cordova > Issue Type: Bug > Components: Plugin File > Affects Versions: 4.1.1 > Environment: Android 6.0.1 (Nexus 9 and other 6.x devices), Cordova cli 6.0.0, Android platform 5.1.0 > Reporter: Vito Macchia > Assignee: Raghav Katyal > Labels: android, triaged > > Cannot create folder into cordova.file.externalRootDirectory on Android 6.x Marshmallow. It always returns encording error (12), while on Android 5.x (Lollipop) the same code works fine. > On Marshmallow devices I can succesfully create folders only into cordova.file.externalDataDirectory. > No matter the value of preference AndroidPersistentFileLocation or AndroidExtraFilesystems. > Code (some ES6, sorry) > This snippet uses WinJS Promises - should work with native promises as well or you can just remove promises and pass succes and fail callbacks. It should create MY_Folder/test (both folders, like mkdirp) in the SD Card (regardless if emulated or not) root directory. It works fine with 5.x devices, but returns always FileError.ENCODING_ERR on Marshmallow. > {code:title=createDirectory.js|borderStyle=solid} > function errorCode(e) { > var msg = ''; > switch (e.code) { > case FileError.ABORT_ERR: > msg = 'ABORT_ERR'; > break; > case FileError.ENCODING_ERR: > msg = 'ENCODING_ERR'; > break; > case FileError.NOT_READABLE_ERR: > msg = 'NOT_READABLE_ERR'; > break; > case FileError.PATH_EXISTS_ERR: > msg = 'PATH_EXISTS_ERR'; > break; > case FileError.QUOTA_EXCEEDED_ERR: > msg = 'QUOTA_EXCEEDED_ERR'; > break; > case FileError.NOT_FOUND_ERR: > msg = 'NOT_FOUND_ERR'; > break; > case FileError.SECURITY_ERR: > msg = 'SECURITY_ERR'; > break; > case FileError.INVALID_MODIFICATION_ERR: > msg = 'INVALID_MODIFICATION_ERR'; > break; > case FileError.INVALID_STATE_ERR: > msg = 'INVALID_STATE_ERR'; > break; > default: > msg = 'Unknown Error'; > break; > }; > console.log('Error: ' + msg, "CODE", e); > return msg; > } > const STATIC_CONTENT_DIR = 'MY_Folder/test'; > function createDirectory(startDirectory = cordova.file.externalRootDirectory) { > return new WinJS.Promise(function(success, fail) { > window.resolveLocalFileSystemURL(startDirectory, function(directory) { > console.log("FS ROOT", directory); > function fileGetDir(path, cb) { > console.log("*** PATH", path); > var fnGetOrCreateDir = function(p, de) { > var entry = p.shift(); > console.log("PATH", path); > if (entry) { > de.getDirectory(entry, { > create: true, > exclusive: false > }, function(dirEntry) { > console.log("CR", dirEntry); > fnGetOrCreateDir(p, dirEntry); > }, fileFSError); > } else > if (cb) cb(de); > }; > if (path) { > var arPath = path.split("/"); > fnGetOrCreateDir(arPath, directory.filesystem.root); > } else { > if (cb) cb(directory); > } > } > fileGetDir(STATIC_CONTENT_DIR, onSuccess); > }, fileFSError); > function fileFSError(e) { > console.log(e.code); > try { > console.log("fileFSError: " + JSON.stringify(e) + errorCode(e)); > fail(e); > } catch (err) { > fail(err); > } > } > function onSuccess(dirEntry) { > console.log(dirEntry.fullPath); > success(dirEntry.fullPath) > } > }); > } > {code} > I suspect it has something to do with the way the storage should be handled on Marshmallow, see for instance http://developer.android.com/guide/topics/data/data-storage.html and https://source.android.com/devices/storage/ -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org