WeaponX86 edited a comment on issue #422:
URL: 
https://github.com/apache/cordova-plugin-file/issues/422#issuecomment-826907351


   > 
   > 
   > @WeaponX86 I have the same issue, any workaround?
   
   Nope. Ended up having to change my recursion method from starting at the 
root to starting with the full path and working down to the root and hoping it 
never hits this path.
   
   > /**
   >    * Create a nested folder from a string in one of the standard 
filesystem locations
   >    * 
   >    * @public
   >    * @memberOf FileApi#
   >    * @param {string} sPath - The absolute folder path (a/b/c)
   >    * @param {function} fnSuccess - Success callback (object)
   >    * @param {function} fnFail - Error callback
   >    */
   
   ```  function createDirectoryAny(sPath, fnSuccess, fnError){
                
                console.log('FileApi: createDirectoryReverse - sPath: ' + 
sPath);
        
                //var aPath = sPath.split('/'); // Doesn't handle protocol 
correctly
                var oPath = Common.splitPath(sPath);
                //console.log(oPath);
                
                var sRoot = oPath['sRoot'].replace('///','//'); // Remove extra 
slash
                var aPath = oPath['aPath'];
                
                aPath.unshift(sRoot); // Append root to start of array
                
                //console.log('aPath',aPath)
                
                // RECURSIVE
                var fnCreate = function(directoryEntry,aPathTemp){
                        
                        //console.log('FileApi: createDirectoryReverse > 
fnCreate directoryEntry',directoryEntry);
                        
                        //console.log(aPathTemp);
                        var sFolder = aPathTemp.shift(); // Affects aPath
                        
                        var sNewPath = directoryEntry.nativeURL + sFolder;
                        
                        // On Android 11, if the folder already exists, calling 
getDirectory will throw an error
   
               //console.log('FileApi: createDirectoryReverse > fnCreate > 
resolve not found: ' + sNewPath);
   
               directoryEntry.getDirectory(sFolder, {
                   create : true,
                   //exclusive: false
               }, function(childDirectoryEntry) {
                   //console.log('FileApi: getDirectory success ' + 
childDirectoryEntry.fullPath);
                   //console.log(directoryEntry);
   
                   if (aPathTemp.length > 0){
                       fnCreate(childDirectoryEntry, aPathTemp);
                   } else {
                       if (typeof(fnSuccess) == 'function'){
                           fnSuccess(childDirectoryEntry);
                       }
                   }
               }, function(error){
                   console.error('FileApi: createDirectoryReverse > 
getDirectory failed to create folder: ' + sFolder + ' under: ' + 
directoryEntry.fullPath + ' error code: ' + error.code);
   
                   if (typeof(fnError) == 'function'){
                       fnError();
                   }
               });
                };
                
   
                var fnResolve = function(iIndex){
                        var sSubPath = aPath.slice(0,iIndex).join('/'); // 
Slice uses 1 index, not zero index
                        
                        if (iIndex > 1) sSubPath += '/'; // Append slash to end 
if not at root
                        
                        //console.log('fnResolve iIndex: ' + iIndex + ' 
sSubPath: ' + sSubPath);
                        
                        resolve(sSubPath,
                        function(oEntry){
                                //console.log('FileApi: createDirectoryAny > 
fnResolve path found: ' + sSubPath);
                                
                                fnCreate(oEntry, aPath.slice(iIndex)); // Break 
recursion
                        },
                        function(){
                                if (iIndex > 1){
                                        fnResolve(iIndex-1);    
                                } else {
                                        console.error('FileApi: 
createDirectoryReverse > fnResolve not found: ' + sSubPath);
                                        
                                        // No valid parent folder found
                                        if (typeof(fnError) == 'function'){
                                                fnError();
                                        }
                                }       
                        });
                }
                
                // ATTEMPT to resolve the full path
                FileApi.resolve(sPath,function(oTarget){        
                        console.log('FileApi: createDirectoryAny path already 
exists: ' + sPath);
   
                        fnSuccess(oTarget);
                },function(){
                        fnResolve(aPath.length); // Find the first parent path 
that already exists
                });
        }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to