From: Szymon Jastrzebski Date: Mon, 19 Feb 2018 11:19:44 +0000 (+0100) Subject: [Archive] Updating cached storages X-Git-Tag: submit/tizen/20180228.082430~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1695db065eb80e86c8b0d994ab9d2f6c071e46a3;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Archive] Updating cached storages Currently the implementation obtains all available storages once, during launching Archive plugin. The fix is based on solution from Filesystem. [Verification] Archive 100% pass rate. Change-Id: If0368d89fef3ac25c95bd7d5cf031d6d635643a4 Signed-off-by: Szymon Jastrzebski --- diff --git a/src/archive/archive_api.js b/src/archive/archive_api.js index 8b59c63c..41a8caac 100755 --- a/src/archive/archive_api.js +++ b/src/archive/archive_api.js @@ -22,23 +22,40 @@ var privUtils_ = xwalk.utils; function CommonFS() {}; CommonFS.cacheVirtualToReal = {}; +CommonFS.isCacheReady = false; +CommonFS.listenerRegistered = false; + +function clearCache() { + CommonFS.cacheVirtualToReal = {}; + CommonFS.isCacheReady = false; +} function _initializeCache() { - try { - var result = native_.callSync('Archive_fetchStorages', {}); + if (CommonFS.isCacheReady) { + return; + } + var result = native_.callSync('Archive_fetchStorages', {}); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + if (native_.isFailure(result)) { + privUtils_.log("Exception while getting widget paths was thrown: " + native_.getErrorObject(result).message); + return; + } - result = native_.getResultObject(result); - for (var i = 0; i < result.length; ++i) { - CommonFS.cacheVirtualToReal[result[i].name] = { - path: result[i].path - }; + result = native_.getResultObject(result); + for (var i = 0; i < result.length; ++i) { + CommonFS.cacheVirtualToReal[result[i].name] = { + path: result[i].path + }; + } + CommonFS.isCacheReady = true; + if (!CommonFS.listenerRegistered) { + try { + tizen.filesystem.addStorageStateChangeListener(clearCache); + CommonFS.listenerRegistered = true; + } catch (e) { + privUtils_.log('Failed to register storage change listener, ' + + 'storage information may be corrupted: ' + e.message); } - } catch(e) { - privUtils_.log("Exception while getting widget paths was thrown: " + e); } } @@ -50,6 +67,7 @@ CommonFS.toRealPath = function(aPath) { _fileRealPath = aPath.substr(_uriPrefix.length); } else if (aPath[0] != '/') { // virtual path$ + _initializeCache(); var _pathTokens = aPath.split('/'); if (this.cacheVirtualToReal[_pathTokens[0]] && (this.cacheVirtualToReal[_pathTokens[0]].state === undefined || this.cacheVirtualToReal[_pathTokens[0]].state === 'MOUNTED')) { @@ -72,7 +90,7 @@ CommonFS.toRealPath = function(aPath) { CommonFS.isVirtualPath = function(aPath) { var root = aPath.split("/")[0]; - + _initializeCache(); return this.cacheVirtualToReal[root] != undefined; };