Merge branch 'tizen_4.0' into tizen_5.0
[platform/core/api/webapi-plugins.git] / src / filesystem / js / common.js
index 61ffe4f..f90e653 100644 (file)
@@ -28,12 +28,12 @@ var native_ = new xwalk.utils.NativeManager(extension);
  * Useful for passing data through crosswalk.
  */
 function StringToArray(str, type) {
-  var len = str.length;
-  var output = new type(len);
-  for (var i = 0; i < len; i++) {
-    output[i] = str.charCodeAt(i);
-  }
-  return output;
+    var len = str.length;
+    var output = new type(len);
+    for (var i = 0; i < len; i++) {
+        output[i] = str.charCodeAt(i);
+    }
+    return output;
 }
 
 /*
@@ -42,29 +42,29 @@ function StringToArray(str, type) {
  * Useful for passing data through crosswalk.
  */
 function ArrayToString(data) {
-  var output = '';
-  var len = data.length;
-  for (var i = 0; i < len; i++) {
-    output += String.fromCharCode(data[i] & 0xFF);  // conversion to octet
-  }
-  return output;
+    var output = '';
+    var len = data.length;
+    for (var i = 0; i < len; i++) {
+        output += String.fromCharCode(data[i] & 0xff); // conversion to octet
+    }
+    return output;
 }
 
 function SetReadOnlyProperty(obj, n, v) {
-  Object.defineProperty(obj, n, {value: v, writable: false});
+    Object.defineProperty(obj, n, { value: v, writable: false });
 }
 
-var FileSystemStorageType = {INTERNAL: 'INTERNAL', EXTERNAL: 'EXTERNAL'};
+var FileSystemStorageType = { INTERNAL: 'INTERNAL', EXTERNAL: 'EXTERNAL' };
 
 var FileSystemStorageState = {
-  MOUNTED: 'MOUNTED',
-  REMOVED: 'REMOVED',
-  UNMOUNTABLE: 'UNMOUNTABLE'
+    MOUNTED: 'MOUNTED',
+    REMOVED: 'REMOVED',
+    UNMOUNTABLE: 'UNMOUNTABLE'
 };
 
-var FileMode = {a: 'a', r: 'r', rw: 'rw', rwo: 'rwo', w: 'w'};
+var FileMode = { a: 'a', r: 'r', rw: 'rw', rwo: 'rwo', w: 'w' };
 
-var BaseSeekPosition = {BEGIN: 'BEGIN', CURRENT: 'CURRENT', END: 'END'};
+var BaseSeekPosition = { BEGIN: 'BEGIN', CURRENT: 'CURRENT', END: 'END' };
 
 var tizen24home = '/opt/usr/media';
 
@@ -73,365 +73,388 @@ var tizen24home = '/opt/usr/media';
 var kVirtualRootImages = 'images';
 
 var commonFS_ = (function() {
-  var cacheReady = false;
-  var listenerRegistered = false;
-  var cacheVirtualToReal = {};
-  var cacheStorages = [];
-  var uriPrefix = 'file://';
-  // special condition for previous versions paths
-  // (global paths usage issue workaround)
-  var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan('3.0');
-  var homeDir = undefined;
-
-  function clearCache() {
-    cacheVirtualToReal = {};
-    cacheStorages = [];
-    cacheReady = false;
-  }
-
-  // initalize home directory for correct mapping global paths from tizen 2.4
-  // (global paths usage issue workaround)
-  function initHomeDir(aPath) {
-    if (homeDir || !isAppForEarlierVersion) {
-      return;
-    }
-    var imagesPath = cacheVirtualToReal[kVirtualRootImages].path;
-
-    if (imagesPath[imagesPath.length - 1] === '/') {
-      homeDir = imagesPath.split('/').slice(0, -2).join('/');
-    } else {
-      homeDir = imagesPath.split('/').slice(0, -1).join('/');
-    }
-  }
+    var cacheReady = false;
+    var listenerRegistered = false;
+    var cacheVirtualToReal = {};
+    var cacheStorages = [];
+    var uriPrefix = 'file://';
+    // special condition for previous versions paths
+    // (global paths usage issue workaround)
+    var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan('3.0');
+    var homeDir = undefined;
 
-  function initCache() {
-    if (cacheReady) {
-      return;
+    function clearCache() {
+        cacheVirtualToReal = {};
+        cacheStorages = [];
+        cacheReady = false;
     }
 
-    var result = native_.callSync('Filesystem_fetchVirtualRoots', {});
-    if (native_.isFailure(result)) {
-      throw native_.getErrorObject(result);
-    }
-    var virtualRoots = native_.getResultObject(result);
-
-    for (var i = 0; i < virtualRoots.length; ++i) {
-      cacheVirtualToReal[virtualRoots[i].name] = {
-        path: virtualRoots[i].path,
-        label: virtualRoots[i].name,
-        type: FileSystemStorageType.INTERNAL,
-        state: FileSystemStorageState.MOUNTED
-      };
-    }
     // initalize home directory for correct mapping global paths from tizen 2.4
     // (global paths usage issue workaround)
-    initHomeDir();
-
-    var result = native_.callSync('FileSystemManager_fetchStorages', {});
-    if (native_.isFailure(result)) {
-      throw native_.getErrorObject(result);
-    }
-
-    var storages = native_.getResultObject(result);
-    for (var i = 0; i < storages.length; ++i) {
-      cacheStorages.push({
-        path: storages[i].path,
-        label: storages[i].name,
-        type: storages[i].type,
-        state: storages[i].state,
-        storage_id: storages[i].storage_id
-      });
+    function initHomeDir(aPath) {
+        if (homeDir || !isAppForEarlierVersion) {
+            return;
+        }
+        var imagesPath = cacheVirtualToReal[kVirtualRootImages].path;
+
+        if (imagesPath[imagesPath.length - 1] === '/') {
+            homeDir = imagesPath
+                .split('/')
+                .slice(0, -2)
+                .join('/');
+        } else {
+            homeDir = imagesPath
+                .split('/')
+                .slice(0, -1)
+                .join('/');
+        }
     }
 
-    if (!listenerRegistered) {
-      try {
-        tizen.filesystem.addStorageStateChangeListener(function() {
-          clearCache();
-        });
-        listenerRegistered = true;
-      } catch (e) {
-        privUtils_.log(
-            'Failed to register storage change listener, ' +
-            'storage information may be corrupted: ' + e.message);
-      }
-    }
+    function initCache() {
+        if (cacheReady) {
+            return;
+        }
 
-    cacheReady = true;
-  }
+        var result = native_.callSync('Filesystem_fetchVirtualRoots', {});
+        if (native_.isFailure(result)) {
+            throw native_.getErrorObject(result);
+        }
+        var virtualRoots = native_.getResultObject(result);
+
+        for (var i = 0; i < virtualRoots.length; ++i) {
+            cacheVirtualToReal[virtualRoots[i].name] = {
+                path: virtualRoots[i].path,
+                label: virtualRoots[i].name,
+                type: FileSystemStorageType.INTERNAL,
+                state: FileSystemStorageState.MOUNTED
+            };
+        }
+        // initalize home directory for correct mapping global paths from tizen 2.4
+        // (global paths usage issue workaround)
+        initHomeDir();
 
-  function mergeMultipleSlashes(str) {
-    var retStr = str.replace(/(^(file\:\/\/\/)|^(file\:\/\/)|\/)\/{0,}/g, '$1');
-    return retStr;
-  }
+        var result = native_.callSync('FileSystemManager_fetchStorages', {});
+        if (native_.isFailure(result)) {
+            throw native_.getErrorObject(result);
+        }
 
-  function removeDotsFromPath(str) {
-    if (str === undefined) {
-      return str;
-    }
+        var storages = native_.getResultObject(result);
+        for (var i = 0; i < storages.length; ++i) {
+            cacheStorages.push({
+                path: storages[i].path,
+                label: storages[i].name,
+                type: storages[i].type,
+                state: storages[i].state,
+                storage_id: storages[i].storage_id
+            });
+        }
 
-    var _pathTokens = str.split('/');
-    var _correctDir = [];
-    var _fileRealPath = _pathTokens[0];
-    _correctDir.push(_pathTokens[0]);
-    for (var i = 1; i < _pathTokens.length; ++i) {
-      if (_pathTokens[i] == '..') {
-        if (_fileRealPath == '') {
-          _fileRealPath = undefined;
-          break;
+        if (!listenerRegistered) {
+            try {
+                tizen.filesystem.addStorageStateChangeListener(function() {
+                    clearCache();
+                });
+                listenerRegistered = true;
+            } catch (e) {
+                privUtils_.log(
+                    'Failed to register storage change listener, ' +
+                        'storage information may be corrupted: ' +
+                        e.message
+                );
+            }
         }
-        var _lastDir = _correctDir.pop();
-        _fileRealPath =
-            _fileRealPath.substring(0, _fileRealPath.length - _lastDir.length - 1);
-      } else if (_pathTokens[i] != '.') {
-        _fileRealPath += '/' + _pathTokens[i];
-        _correctDir.push(_pathTokens[i]);
-      }
-    }
-    return _fileRealPath;
-  }
 
-  function checkPathWithoutDots(aPath) {
-    if (-1 !== aPath.indexOf('/../')) {
-      return false;
+        cacheReady = true;
     }
-    if (-1 !== aPath.indexOf('/./')) {
-      return false;
+
+    function mergeMultipleSlashes(str) {
+        var retStr = str.replace(/(^(file\:\/\/\/)|^(file\:\/\/)|\/)\/{0,}/g, '$1');
+        return retStr;
     }
-    // check if path ends with '/.' or '/..'
-    if (aPath.match(/\/\.\.?$/)) {
-      return false;
+
+    function removeDotsFromPath(str) {
+        if (str === undefined) {
+            return str;
+        }
+
+        var _pathTokens = str.split('/');
+        var _correctDir = [];
+        var _fileRealPath = _pathTokens[0];
+        _correctDir.push(_pathTokens[0]);
+        for (var i = 1; i < _pathTokens.length; ++i) {
+            if (_pathTokens[i] == '..') {
+                if (_fileRealPath == '') {
+                    _fileRealPath = undefined;
+                    break;
+                }
+                var _lastDir = _correctDir.pop();
+                _fileRealPath = _fileRealPath.substring(
+                    0,
+                    _fileRealPath.length - _lastDir.length - 1
+                );
+            } else if (_pathTokens[i] != '.') {
+                _fileRealPath += '/' + _pathTokens[i];
+                _correctDir.push(_pathTokens[i]);
+            }
+        }
+        return _fileRealPath;
     }
-    // check if path starts with './' or '../'
-    if (aPath.match(/^\.\.?\//)) {
-      return false;
+
+    function checkPathWithoutDots(aPath) {
+        if (-1 !== aPath.indexOf('/../')) {
+            return false;
+        }
+        if (-1 !== aPath.indexOf('/./')) {
+            return false;
+        }
+        // check if path ends with '/.' or '/..'
+        if (aPath.match(/\/\.\.?$/)) {
+            return false;
+        }
+        // check if path starts with './' or '../'
+        if (aPath.match(/^\.\.?\//)) {
+            return false;
+        }
+        return true;
     }
-    return true;
-  }
-
-  function convertForEarlierVersionPath(aPath) {
-    if (isAppForEarlierVersion) {
-      if (aPath && aPath.indexOf(tizen24home) === 0) {
-        privUtils_.log('Converting 2.4 style path to 3.0 pattern');
-        aPath = homeDir + aPath.substr(tizen24home.length);
-      }
+
+    function convertForEarlierVersionPath(aPath) {
+        if (isAppForEarlierVersion) {
+            if (aPath && aPath.indexOf(tizen24home) === 0) {
+                privUtils_.log('Converting 2.4 style path to 3.0 pattern');
+                aPath = homeDir + aPath.substr(tizen24home.length);
+            }
+        }
+        return aPath;
     }
-    return aPath;
-  }
 
-  function toRealPath(aPath) {
-    var _fileRealPath = '';
+    function toRealPath(aPath) {
+        var _fileRealPath = '';
+
+        aPath = mergeMultipleSlashes(aPath);
+
+        if (aPath.indexOf(uriPrefix) === 0) {
+            _fileRealPath = aPath.substr(uriPrefix.length);
+        } else if (aPath[0] !== '/') {
+            // virtual path
+            initCache();
+
+            var _pathTokens = aPath.split('/');
+
+            if (cacheVirtualToReal[_pathTokens[0]]) {
+                _fileRealPath = cacheVirtualToReal[_pathTokens[0]].path;
+                for (var i = 1; i < _pathTokens.length; ++i) {
+                    _fileRealPath += '/' + _pathTokens[i];
+                }
+            } else {
+                // If path token is not present in cache then it is invalid
+                _fileRealPath = undefined;
+                // check storages
+                for (var j = 0; j < cacheStorages.length; ++j) {
+                    if (cacheStorages[j].label === _pathTokens[0]) {
+                        _fileRealPath = cacheStorages[j].path;
+                        for (var i = 1; i < _pathTokens.length; ++i) {
+                            _fileRealPath += '/' + _pathTokens[i];
+                        }
+                        break;
+                    }
+                }
+            }
+        } else {
+            _fileRealPath = aPath;
+        }
+        // removeDotsFromPath execution here, results with '.' and '..' beeing
+        // supported in paths, next methods throw an error when getting argument
+        // with '.' or '..' in it
+        // (see commonFS_.checkPathWithoutDots() method)
+        _fileRealPath = removeDotsFromPath(_fileRealPath);
+        // convert path to be compatibile with previous version of Tizen
+        // (global paths usage issue workaround)
+        _fileRealPath = convertForEarlierVersionPath(_fileRealPath);
+        // if path is valid try to cut last '/' if it is present
+        if (_fileRealPath) {
+            _fileRealPath = mergeMultipleSlashes(_fileRealPath);
+        }
+        return _fileRealPath;
+    }
 
-    aPath = mergeMultipleSlashes(aPath);
+    function toVirtualPath(aPath) {
+        aPath = mergeMultipleSlashes(aPath);
+        var _virtualPath = aPath;
 
-    if (aPath.indexOf(uriPrefix) === 0) {
-      _fileRealPath = aPath.substr(uriPrefix.length);
-    } else if (aPath[0] !== '/') {
-      // virtual path
-      initCache();
+        if (_virtualPath.indexOf(uriPrefix) === 0) {
+            _virtualPath = _virtualPath.substr(uriPrefix.length);
+        }
 
-      var _pathTokens = aPath.split('/');
+        initCache();
 
-      if (cacheVirtualToReal[_pathTokens[0]]) {
-        _fileRealPath = cacheVirtualToReal[_pathTokens[0]].path;
-        for (var i = 1; i < _pathTokens.length; ++i) {
-          _fileRealPath += '/' + _pathTokens[i];
-        }
-      } else {
-        // If path token is not present in cache then it is invalid
-        _fileRealPath = undefined;
-        // check storages
-        for (var j = 0; j < cacheStorages.length; ++j) {
-          if (cacheStorages[j].label === _pathTokens[0]) {
-            _fileRealPath = cacheStorages[j].path;
-            for (var i = 1; i < _pathTokens.length; ++i) {
-              _fileRealPath += '/' + _pathTokens[i];
+        for (var virtual_root in cacheVirtualToReal) {
+            var real_root_path = cacheVirtualToReal[virtual_root].path;
+            if (_virtualPath.indexOf(real_root_path, 0) === 0) {
+                return _virtualPath.replace(real_root_path, virtual_root);
             }
-            break;
-          }
         }
-      }
-    } else {
-      _fileRealPath = aPath;
-    }
-    // removeDotsFromPath execution here, results with '.' and '..' beeing supported in
-    // paths, next methods throw an error when getting argument with '.' or '..' in it
-    // (see commonFS_.checkPathWithoutDots() method)
-    _fileRealPath = removeDotsFromPath(_fileRealPath);
-    // convert path to be compatibile with previous version of Tizen
-    // (global paths usage issue workaround)
-    _fileRealPath = convertForEarlierVersionPath(_fileRealPath);
-    // if path is valid try to cut last '/' if it is present
-    if (_fileRealPath) {
-      _fileRealPath = mergeMultipleSlashes(_fileRealPath);
+
+        return _virtualPath;
     }
-    return _fileRealPath;
-  }
 
-  function toVirtualPath(aPath) {
-    aPath = mergeMultipleSlashes(aPath);
-    var _virtualPath = aPath;
+    function getFileInfo(aStatObj, secondIter, aMode) {
+        var _result = {},
+            _pathTokens,
+            _fileParentPath = '',
+            i;
+        var aPath = toVirtualPath(aStatObj.path);
+
+        _result.readOnly = aStatObj.readOnly;
+        _result.isFile = aStatObj.isFile;
+        _result.isDirectory = aStatObj.isDirectory;
+        _result.created = new Date(aStatObj.ctime * 1000);
+        _result.modified = new Date(aStatObj.mtime * 1000);
+        _result.fullPath = aPath;
+        _result.fileSize = aStatObj.size;
+        _result.mode = aMode;
+        if (_result.isDirectory) {
+            try {
+                _result.length = aStatObj.nlink;
+            } catch (err) {
+                _result.length = 0;
+            }
+        } else {
+            _result.length = undefined;
+        }
 
-    if (_virtualPath.indexOf(uriPrefix) === 0) {
-      _virtualPath = _virtualPath.substr(uriPrefix.length);
+        _pathTokens = aPath.split('/');
+        if (_pathTokens.length > 1) {
+            var last = _pathTokens.length - 1;
+            var lastToken = '';
+            if (_pathTokens[last] === '') {
+                // 'abc/d/e/' case with trailing '/' sign
+                last = _pathTokens.length - 2;
+                lastToken = '/';
+            }
+            for (i = 0; i < last; ++i) {
+                _fileParentPath += _pathTokens[i] + '/';
+            }
+            if (last > 0) {
+                _result.path = _fileParentPath;
+                _result.name = secondIter
+                    ? _pathTokens[last]
+                    : _pathTokens[last] + lastToken;
+                _result.parent = secondIter ? null : _fileParentPath;
+            } else {
+                // '/' dir case
+                _result.path = _pathTokens[last] + lastToken;
+                _result.name = '';
+                _result.parent = secondIter ? null : _fileParentPath;
+            }
+        } else {
+            _result.parent = null;
+            _result.path = aPath;
+            _result.name = '';
+        }
+        return _result;
     }
 
-    initCache();
+    function isLocationAllowed(aPath) {
+        if (!aPath) {
+            return false;
+        }
+        initCache();
+        if (aPath.indexOf(cacheVirtualToReal.ringtones.path) === 0) {
+            return false;
+        }
+        if (aPath.indexOf(cacheVirtualToReal['wgt-package'].path) === 0) {
+            return false;
+        }
 
-    for (var virtual_root in cacheVirtualToReal) {
-      var real_root_path = cacheVirtualToReal[virtual_root].path;
-      if (_virtualPath.indexOf(real_root_path, 0) === 0) {
-        return _virtualPath.replace(real_root_path, virtual_root);
-      }
+        return true;
     }
 
-    return _virtualPath;
-  }
-
-  function getFileInfo(aStatObj, secondIter, aMode) {
-    var _result = {}, _pathTokens, _fileParentPath = '', i;
-    var aPath = toVirtualPath(aStatObj.path);
-
-    _result.readOnly = aStatObj.readOnly;
-    _result.isFile = aStatObj.isFile;
-    _result.isDirectory = aStatObj.isDirectory;
-    _result.created = new Date(aStatObj.ctime * 1000);
-    _result.modified = new Date(aStatObj.mtime * 1000);
-    _result.fullPath = aPath;
-    _result.fileSize = aStatObj.size;
-    _result.mode = aMode;
-    if (_result.isDirectory) {
-      try {
-        _result.length = aStatObj.nlink;
-      } catch (err) {
-        _result.length = 0;
-      }
-    } else {
-      _result.length = undefined;
-    }
+    function toCanonicalPath(path) {
+        var result = native_.callSync('FileSystemManager_getCanonicalPath', {
+            path: path
+        });
+        if (native_.isFailure(result)) {
+            throw native_.getErrorObject(result);
+        }
 
-    _pathTokens = aPath.split('/');
-    if (_pathTokens.length > 1) {
-      var last = _pathTokens.length - 1;
-      var lastToken = '';
-      if (_pathTokens[last] === '') {
-        // 'abc/d/e/' case with trailing '/' sign
-        last = _pathTokens.length - 2;
-        lastToken = '/';
-      }
-      for (i = 0; i < last; ++i) {
-        _fileParentPath += _pathTokens[i] + '/';
-      }
-      if (last > 0) {
-        _result.path = _fileParentPath;
-        _result.name = (secondIter) ? _pathTokens[last] : _pathTokens[last] + lastToken;
-        _result.parent = (secondIter) ? null : _fileParentPath;
-      } else {
-        // '/' dir case
-        _result.path = _pathTokens[last] + lastToken;
-        _result.name = '';
-        _result.parent = (secondIter) ? null : _fileParentPath;
-      }
-    } else {
-      _result.parent = null;
-      _result.path = aPath;
-      _result.name = '';
+        return native_.getResultObject(result);
     }
-    return _result;
-  }
 
-  function isLocationAllowed(aPath) {
-    if (!aPath) {
-      return false;
-    }
-    initCache();
-    if (aPath.indexOf(cacheVirtualToReal.ringtones.path) === 0) {
-      return false;
-    }
-    if (aPath.indexOf(cacheVirtualToReal['wgt-package'].path) === 0) {
-      return false;
-    }
+    function f_isSubDir(fullPathToCheck, fullPath) {
+        var fullCanonicalPathToCheck = toCanonicalPath(toRealPath(fullPathToCheck));
+        var fullCanonicalPath = toCanonicalPath(toRealPath(fullPath));
 
-    return true;
-  }
+        if (fullCanonicalPathToCheck === fullCanonicalPath) {
+            return false;
+        }
 
-  function toCanonicalPath(path) {
-    var result = native_.callSync('FileSystemManager_getCanonicalPath', {'path': path});
-    if (native_.isFailure(result)) {
-      throw native_.getErrorObject(result);
+        return fullCanonicalPathToCheck.indexOf(fullCanonicalPath) === 0;
     }
 
-    return native_.getResultObject(result);
-  }
-
-  function f_isSubDir(fullPathToCheck, fullPath) {
-    var fullCanonicalPathToCheck = toCanonicalPath(toRealPath(fullPathToCheck));
-    var fullCanonicalPath = toCanonicalPath(toRealPath(fullPath));
-
-    if (fullCanonicalPathToCheck === fullCanonicalPath) {
-      return false;
+    function f_isCorrectRelativePath(relativePath) {
+        return (
+            0 !== relativePath.indexOf('/') &&
+            0 !== relativePath.indexOf('\\') &&
+            -1 === relativePath.indexOf('?') &&
+            -1 === relativePath.indexOf('*') &&
+            -1 === relativePath.indexOf(':') &&
+            -1 === relativePath.indexOf('"') &&
+            -1 === relativePath.indexOf('<') &&
+            -1 === relativePath.indexOf('>')
+        );
     }
 
-    return fullCanonicalPathToCheck.indexOf(fullCanonicalPath) === 0;
-  }
-
-  function f_isCorrectRelativePath(relativePath) {
-    return (
-        (0 !== relativePath.indexOf('/')) && (0 !== relativePath.indexOf('\\')) &&
-        (-1 === relativePath.indexOf('?')) && (-1 === relativePath.indexOf('*')) &&
-        (-1 === relativePath.indexOf(':')) && (-1 === relativePath.indexOf('"')) &&
-        (-1 === relativePath.indexOf('<')) && (-1 === relativePath.indexOf('>')));
-  };
-
-  function cloneStorage(storage) {
-    return {label: storage.label, type: storage.type, state: storage.state};
-  }
-
-  function getStorage(label) {
-    initCache();
-    for (var i = 0; i < cacheStorages.length; ++i) {
-      if (cacheStorages[i].label === label) {
-        return cloneStorage(cacheStorages[i]);
-      }
+    function cloneStorage(storage) {
+        return { label: storage.label, type: storage.type, state: storage.state };
     }
 
-    for (var key in cacheVirtualToReal) {
-      if (cacheVirtualToReal.hasOwnProperty(key)) {
-        if (cacheVirtualToReal[key].label === label) {
-          return cloneStorage(cacheVirtualToReal[key]);
+    function getStorage(label) {
+        initCache();
+        for (var i = 0; i < cacheStorages.length; ++i) {
+            if (cacheStorages[i].label === label) {
+                return cloneStorage(cacheStorages[i]);
+            }
         }
-      }
-    }
 
-    return null;
-  }
+        for (var key in cacheVirtualToReal) {
+            if (cacheVirtualToReal.hasOwnProperty(key)) {
+                if (cacheVirtualToReal[key].label === label) {
+                    return cloneStorage(cacheVirtualToReal[key]);
+                }
+            }
+        }
 
-  function getAllStorages() {
-    var ret = [];
-    initCache();
-    for (var i = 0; i < cacheStorages.length; ++i) {
-      ret.push(cloneStorage(cacheStorages[i]));
+        return null;
     }
 
-    for (var key in cacheVirtualToReal) {
-      if (cacheVirtualToReal.hasOwnProperty(key)) {
-        ret.push(cloneStorage(cacheVirtualToReal[key]));
-      }
+    function getAllStorages() {
+        var ret = [];
+        initCache();
+        for (var i = 0; i < cacheStorages.length; ++i) {
+            ret.push(cloneStorage(cacheStorages[i]));
+        }
+
+        for (var key in cacheVirtualToReal) {
+            if (cacheVirtualToReal.hasOwnProperty(key)) {
+                ret.push(cloneStorage(cacheVirtualToReal[key]));
+            }
+        }
+
+        return ret;
     }
 
-    return ret;
-  }
-
-  return {
-    clearCache: clearCache,
-    checkPathWithoutDots: checkPathWithoutDots,
-    toRealPath: toRealPath,
-    toVirtualPath: toVirtualPath,
-    getFileInfo: getFileInfo,
-    isLocationAllowed: isLocationAllowed,
-    f_isSubDir: f_isSubDir,
-    f_isCorrectRelativePath: f_isCorrectRelativePath,
-    getStorage: getStorage,
-    getAllStorages: getAllStorages,
-    mergeMultipleSlashes: mergeMultipleSlashes
-  };
+    return {
+        clearCache: clearCache,
+        checkPathWithoutDots: checkPathWithoutDots,
+        toRealPath: toRealPath,
+        toVirtualPath: toVirtualPath,
+        getFileInfo: getFileInfo,
+        isLocationAllowed: isLocationAllowed,
+        f_isSubDir: f_isSubDir,
+        f_isCorrectRelativePath: f_isCorrectRelativePath,
+        getStorage: getStorage,
+        getAllStorages: getAllStorages,
+        mergeMultipleSlashes: mergeMultipleSlashes
+    };
 })();