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);
}
}
_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')) {
CommonFS.isVirtualPath = function(aPath) {
var root = aPath.split("/")[0];
-
+ _initializeCache();
return this.cacheVirtualToReal[root] != undefined;
};