[Filesystem] Fix File.fullPath property. Fix virtual path resolving
authorKamil Lysik <k.lysik@samsung.com>
Tue, 10 Mar 2015 10:59:17 +0000 (11:59 +0100)
committerRafal Galka <r.galka@samsung.com>
Thu, 12 Mar 2015 09:42:46 +0000 (18:42 +0900)
File.fullPath property returned real path that is not expected.
This property should return virtual path.
Moreover, cacheRealToVirtual was removed as obsolete.

[Verification]
TCT tests should pass.
File.fullPath property should return virtual root path.

Change-Id: I8cd712e0830e38e7823bcb8b902830385d2b24cb
Signed-off-by: Kamil Lysik <k.lysik@samsung.com>
src/filesystem/js/common.js
src/filesystem/js/file.js
src/filesystem/js/file_system_manager.js

index 870d18f119c6297bf7977b994ae2ed0caedc901e..13770332a5ea7d80fea7cd9306511a535983d052 100644 (file)
@@ -49,31 +49,21 @@ function CommonFS() {
 
 CommonFS.prototype.cacheVirtualToReal = {};
 
-CommonFS.prototype.cacheRealToVirtual = {};
-
 CommonFS.prototype.cacheStorages = [];
 
-CommonFS.prototype.getFileInfo = function(aPath, aStatObj, secondIter, aMode) {
+CommonFS.prototype.getFileInfo = function(aStatObj, secondIter, aMode) {
   var _result = {},
       _pathTokens,
       _fileParentPath = '',
       i;
-
-  if (aPath.indexOf('file://') === 0) {
-    aPath = aPath.substr('file://'.length);
-  }
-
-  if (aPath[0] === '/') {
-    aPath = aPath.substr(1);
-    _fileParentPath = '/';
-  }
+  var aPath = this.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 = _fileParentPath + aPath;
+  _result.fullPath = aPath;
   _result.fileSize = aStatObj.size;
   _result.mode = aMode;
   if (_result.isDirectory) {
@@ -96,8 +86,8 @@ CommonFS.prototype.getFileInfo = function(aPath, aStatObj, secondIter, aMode) {
     _result.parent = (secondIter) ? null : _fileParentPath;
   } else {
     _result.parent = null;
-    _result.path = _fileParentPath === '/' ? _fileParentPath : aPath;
-    _result.name = _fileParentPath === '/' ? aPath : '';
+    _result.path = aPath;
+    _result.name = '';
   }
   return _result;
 };
@@ -147,7 +137,6 @@ CommonFS.prototype.toRealPath = function(aPath) {
       for (i = 1; i < _pathTokens.length; ++i) {
         _fileRealPath += '/' + _pathTokens[i];
       }
-      this.cacheRealToVirtual[_fileRealPath] = aPath;
     } else {
       //If path token is not present in cache then it is invalid
       _fileRealPath = undefined;
@@ -164,11 +153,11 @@ CommonFS.prototype.toVirtualPath = function(aPath) {
   if (_virtualPath.indexOf('file://') === 0) {
     _virtualPath = _virtualPath.substr('file://'.length);
   }
-  for (var real_path in this.cacheRealToVirtual) {
-    if (_virtualPath.indexOf(real_path) === 0) {
-      return _virtualPath.replace(
-          real_path,
-          this.cacheRealToVirtual[real_path]);
+
+  for (var virtual_root in this.cacheVirtualToReal) {
+    var real_root_path = this.cacheVirtualToReal[virtual_root].path;
+    if (aPath.indexOf(real_root_path, 0) === 0) {
+        return aPath.replace(real_root_path, virtual_root)
     }
   }
 
@@ -202,10 +191,6 @@ CommonFS.prototype.initCache = function() {
     state: FileSystemStorageState.MOUNTED
   };
 
-  this.cacheRealToVirtual[widgetsPaths['wgt-package']] = 'wgt-package';
-  this.cacheRealToVirtual[widgetsPaths['wgt-private']] = 'wgt-private';
-  this.cacheRealToVirtual[widgetsPaths['wgt-private-tmp']] = 'wgt-private-tmp';
-
   var d = this.cacheVirtualToReal;
   for (var i in d) {
     this.cacheStorages.push({
@@ -235,7 +220,6 @@ CommonFS.prototype.initCache = function() {
           storage_id: data[i].storage_id
         });
       }
-      this.cacheRealToVirtual[data[i].paths[j]] = j;
     }
     this.cacheStorages.push({
       label: data[i].name,
@@ -247,7 +231,6 @@ CommonFS.prototype.initCache = function() {
 };
 
 CommonFS.prototype.clearCache = function() {
-  this.cacheRealToVirtual = {};
   this.cacheVirtualToReal = {};
   this.cacheStorages = [];
 };
index dfcf49ab2709357db6b1b51448b34738d168fab2..f041d9ec7b309d6fbdaa92749559a89ac908bfc2 100644 (file)
@@ -20,7 +20,7 @@ function File(data) {
             var _location = {location: commonFS_.toRealPath(_parentPath)};
             var _result = native_.callSync('File_statSync', _location);
             var _statObj = native_.getResultObject(_result);
-            var _info = commonFS_.getFileInfo(_parentPath, _statObj, true);
+            var _info = commonFS_.getFileInfo(_statObj, true);
             return new File(_info);
           } else {
             return null;
@@ -184,13 +184,11 @@ File.prototype.listFiles = function(onsuccess, onerror, filter) {
     var aFiles = native_.getResultObject(result);
     var _result = [],
         i,
-        _resolvedPath,
         _statObj,
         _fileInfo;
     for (i = 0; i < aFiles.length; ++i) {
-      _resolvedPath = aFiles[i].path;
       _statObj = aFiles[i];
-      _fileInfo = commonFS_.getFileInfo(_resolvedPath, _statObj);
+      _fileInfo = commonFS_.getFileInfo(_statObj);
 
       if (_fileFilter === null) {
         _result.push(new File(_fileInfo));
@@ -548,7 +546,7 @@ File.prototype.createDirectory = function(dirPath) {
     var _result = native_.callSync('File_statSync', {location: _realNewPath});
     _statObj = native_.getResultObject(_result);
 
-    _fileInfo = commonFS_.getFileInfo(_realNewPath, _statObj, false, this.mode);
+    _fileInfo = commonFS_.getFileInfo(_statObj, false, this.mode);
     return new File(_fileInfo);
   } else {
     throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR,
@@ -598,7 +596,7 @@ File.prototype.createFile = function(relativeFilePath) {
 
   var _result = native_.callSync('File_statSync', {location: _outputRealPath});
   var _statObj = native_.getResultObject(_result);
-  var _fileInfo = commonFS_.getFileInfo(_outputPath, _statObj, false, this.mode);
+  var _fileInfo = commonFS_.getFileInfo(_statObj, false, this.mode);
 
   return new File(_fileInfo);
 
@@ -637,7 +635,7 @@ File.prototype.resolve = function(filePath) {
     throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR, native_.getErrorObject(_result));
   }
   var _statObj = native_.getResultObject(_result);
-  var _fileInfo = commonFS_.getFileInfo(_newPath, _statObj, false, this.mode);
+  var _fileInfo = commonFS_.getFileInfo(_statObj, false, this.mode);
   return new File(_fileInfo);
 
 };
@@ -673,7 +671,7 @@ File.prototype.deleteDirectory = function(directoryPath, recursive, onsuccess, o
     return;
   }
   var _statObj = native_.getResultObject(_result);
-  var _info = commonFS_.getFileInfo(_myPath, _statObj);
+  var _info = commonFS_.getFileInfo(_statObj);
   var _node = new File(_info);
 
   if (!_node.isDirectory) {
index 0bd6041c9dff17f377cc4ce3e3989fa5a0924fce..5f0f5f3ea0f9659ab3e5d8c9a897dfe5f4950ad0 100644 (file)
@@ -62,14 +62,7 @@ FileSystemManager.prototype.resolve = function(location, onsuccess, onerror, mod
     }
 
     var aStatObj = native_.getResultObject(result);
-
-    var _result;
-    var _path = (args.location.indexOf('file://') === 0) ?
-            commonFS_.toVirtualPath(args.location) : args.location;
-    if (_path[_path.length - 1] === '/') {
-      _path = _path.substr(0, _path.length - 1);
-    }
-    _result = commonFS_.getFileInfo(_path, aStatObj, false, args.mode);
+    var _result = commonFS_.getFileInfo(aStatObj, false, args.mode);
     if (_result.readOnly && args.mode !== 'r') {
       throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR);
     } else {