当存储空间快满时出现的bug

##bug说明

  • Creator 版本: 2.4.2

  • 目标平台:微信小游戏

  • 重现方式:当存储空间快满时,从远程下载zip解压,解压时发现存储空间不足无法解压成功,从而导致引擎重新去下载zip包,重新去解压,一直循环三次后失败,无法进入游戏

adapter.js中的代码

unzipAndCacheBundle: function unzipAndCacheBundle(id, zipFilePath, cacheBundleRoot, onComplete) {
    var time = Date.now().toString();
    var targetPath = "".concat(this.cacheDir, "/").concat(cacheBundleRoot, "/").concat(time).concat(suffix++);
    var self = this;
    makeDirSync(targetPath, true);
    unzip(zipFilePath, targetPath, function (err) {
      if (err) {    // 此时err打印的错误是fail the maximum size of the file storage limit is exceeded fail
        rmdirSync(targetPath, true);      // 这时删除的是解压的目标目录,但实际上这个目录还没有创建,微信api提示删除失败,从而也没有起到删除缓存的效果
        onComplete && onComplete(err);
        return;
      }

     ...
     ...
  }
};

因为无法判断是否存储空间快满了,所以我的暂时的解决办法是,在err中根据err.message判断是否是因为存储空间满导致的,如果是就调用cc.assetManager.cacheManager.clearLRU(),然后重新调用unzipAndCacheBundle,避免重复去下载