Chrome App, persistent FileSystem, files lost after chrome restarts

时间秒杀一切 提交于 2019-12-25 03:04:25

问题


I'm developing a Chrome App which uses HTML5 FileSystem with persistent storage, my data was lost after chrome get restarted, I tested several times, 9 times out of 10 data lost after restart, I have fired an issue on Chromium site, I want to know if there is workaround or something I did mistake. here is my code:

window.webkitRequestFileSystem(window.PERSISTENT, 120*1024*1024, function(fs) {
    function gotFileEntry(fileEntry) {
        fileEntry.createWriter(gotFileWriter, fail);
    }

    function gotFileWriter(writer) {
        writer.onwriteend = function(evt) {
            done && done();
        };      
        writer.write(blob);
    }
    fs.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
}, fail);

I found a similar question some guy had asked, but I am sure I set quota(120M) big enough. This problem is for Chrome App, for Legacy packaged app, no problem.

UPDATE: Chrome team has confirmed this problem, the patch will land on Chrome 37.


回答1:


Answer my own question :) I think I found the problem, it does a chrome bug but just happen when you uninstall your app then re-install same app without restart chrome, for somehow reason, chrome remember the uninstalled apps, it will "delay" to clean up filesystem when chrome next time restarts.

This problem may more serious than you think, if you want the re-installed app works correctly, you have to restart ALL of your computers with same Google account after you uninstall old one at same time, you must make sure all copies are uninstalled from all devices before you re-install, Google will snyc new app to you all devices. otherwise you will get problem when you use that app on one of un-restarted computer.

I have added a comment to my issue to Chrome, wish they will fix it.




回答2:


Try this:

  1. Request unlimitedStorage in the manifest:

    "permissions": [ "unlimitedStorage" ]

  2. Use a size of zero in the API call:

    webkitRequestFileSystem(PERSISTENT, 0, haveFileSystem, errorHandler);

In theory the user should be asked to approve a request for some size, but after much testing I've determined that Chrome Apps never do this. Instead, a Chrome App just uses what it wants, similar to apps on OS X, Linux, Windows, etc.



来源:https://stackoverflow.com/questions/23755696/chrome-app-persistent-filesystem-files-lost-after-chrome-restarts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!