title: Chrome App Persistent Filesystem Storage not reliable
body: <p>I am having issues with my google chrome app and filestorage.</p>
  
  <p>The app is run online and gathers files to store offline so that it should be able to function properly offline later. It does this for the most part but <em>sometimes</em> but rarely after a computer restart or restarting the browser it seems to be missing the files in filesystem...</p>
  
  <p>I guess my question is, how do i ensure that Persistent storage remains persistent?</p>
  
  <p><strong>Edit:</strong></p>
  
  <h2>Code</h2>
  
  <p><strong>Request filesystem</strong></p>
  
  <pre><code>window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
  window.requestFileSystem(
  window.PERSISTENT, 200*1024*1024,
      function(filesystem) {
          directory.fs = filesystem;
          //Start Application
      },
      filesystemerrorHandler
  );
  </code></pre>
  
  <p><strong>Save a File from remote to local filesystem</strong></p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.open('GET', fileurl, true);
  xhr.responseType = 'blob';
  xhr.send();
  xhr.onload = function(e) {
      if (this.status == 200) {
          var blob = new Blob([this.response], {type: blobtype});
          directory.fs.root.getFile(name, {create: true}, function(fileEntry) {
              fileEntry.createWriter(function(writer) {
                  writer.onwrite = function(e) {};
                  writer.onerror = function(e) { console.log("error"); console.log(e); };
                  var blob = new Blob([xhr.response], {type: blobtype});
                  writer.write(blob);
                  var url = fileEntry.toURL();
                  if ( typeof(callback) == 'function' ) {
                      //Save url to indexeddb for recall later
                      //Returns format of: filesystem:chrome-extension://nlipipdnicabdffnohdhhliiajoonmgm/persistent/xxxxxxxxxxxx.png
                      callback(url);    
                  }
              }, filewriteerrorHandler2);
          }, filewriteerrorHandler);
      }
      else {
          if ( typeof(callback) == 'function' ) callback(false);
      }
  };
  </code></pre>
  
  <p><strong>Recalling the downloaded file example</strong></p>
  
  <pre><code>&lt;img src="filesystem:chrome-extension://nlipipdnicabdffnohdhhliiajoonmgm/persistent/xxxxxxxxxxxx.png"&gt;
  </code></pre>
  
  <p>Now for the most part this will work. However, sometimes, if the computer has been restarted or the browser restarted. If I use the app again the image will not show, this is giving me the impression that the filesystem has been cleared for this app.</p>
  
  <p>What steps, or what area should I be looking at to prevent this from happening?</p>
  
  <p>Thanks.</p>