Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-7253

window.requestFileSystem fails when no sd card is present and non-zero value is provided for size

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.5.0
    • None
    • cordova-plugin-file
    • I discovered this issue on a Nexus7 emulator running android 4.4.2 with no sd card.

    Description

      The problem is that when no external storage is present the size parameter is compared to the available storage space on the internal file system which is incorrectly reported as 0. After reading a post on stack overflow (http://stackoverflow.com/questions/4799643/getting-all-the-total-and-available-space-on-android) I noticed that they were checking available space in a different way so I tried it and the issue went away.

      You can see this bug in action by setting up an emulator as I described and running an app with the file plugin that can execute the following javascript:

      window.requestFileSystem(PERSISTENT, 1024, function(fs)

      { console.log(fs); }

      , function(e)

      { console.log(e); }

      );

      With the current release you will get an error related to reaching the storage quota since the available space is reported incorrectly. Change line 72 of src/android/DirectoryManager.java to read the following:

      freeSpace = freeSpaceCalculation(Environment.getRootDirectory().getAbsolutePath());

      Run the same line of javascript as before and you will now have success, assuming you actually have the available space.

      You can easily bypass this issue and access the filesystem by just passing 0 for the size but doing so will also circumvent the checks that ensure you don't try to use more space than is available. In my case, my app was handicapping itself because it thought it didn't have enough space to download additional resources when it should not have had any issues.

      Attachments

        Activity

          People

            jasongin Jason Ginchereau
            vscuorzo Vincent Scuorzo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: