[Filesystem] Fixed path-name issue 93/70893/2
authorPiotr Kosko <p.kosko@samsung.com>
Tue, 3 Nov 2015 13:07:39 +0000 (14:07 +0100)
committerbg.chun <bg.chun@samsung.com>
Mon, 23 May 2016 07:49:42 +0000 (16:49 +0900)
[Bug] Values of path and name in File object do not follow documentation when resolve paths with trailing '/' sign.

[Verification] TCT of filesystem, alarm, archive, exif and security 100% passrate.

Scenarios below are correct as in comments:
tizen.filesystem.resolve('/', function(v){console.log("path \"" + v.path + "\" name \"" + v.name + "\"")},
   function(){}, 'r');
// return path "/" name ""

tizen.filesystem.resolve('/opt', function(v){console.log("path \"" + v.path + "\" name \"" + v.name + "\"")},
   function(){}, 'r');
// return path "/" name "opt"

tizen.filesystem.resolve('/opt/', function(v){console.log("path \"" + v.path + "\" name \"" + v.name + "\"")},
   function(){}, 'r');
// return path "/" name "opt/"

tizen.filesystem.resolve('documents', function(v){console.log("path \"" + v.path + "\" name \"" + v.name + "\"")},
   function(){}, 'r');
// return path "documents" name ""

tizen.filesystem.resolve('documents/', function(v){console.log("path \"" + v.path + "\" name \"" + v.name + "\"")},
   function(){}, 'r');
// return path "documents/" name ""

tizen.filesystem.resolve('documents/file.txt', function(v){console.log("path \"" + v.path + "\" name \"" + v.name + "\"")},
   function(){}, 'r');
// return path "documents/" name "file.txt"

Change-Id: I1090a9c40d3ec30953631f5ce9c40fe5acff5f72
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/filesystem/js/common.js
src/filesystem/js/file.js

index fb450eb6474252548fe52cb1906e97ff4d073a59..17fb69d969e584ba6a2087b18857d02b789fbc3d 100644 (file)
@@ -199,12 +199,26 @@ var commonFS_ = (function() {
 
     _pathTokens = aPath.split('/');
     if (_pathTokens.length > 1) {
-      for (i = 0; i < _pathTokens.length - 1; ++i) {
+      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] + '/';
       }
-      _result.path = _fileParentPath;
-      _result.name = _pathTokens[_pathTokens.length - 1];
-      _result.parent = (secondIter) ? null : _fileParentPath;
+      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;
index 973b3c0c577c92151f1b8bec36775dfd933924e4..3d7cbb1577271db0f6909ecabcd118280e66f6b6 100644 (file)
@@ -27,7 +27,7 @@ function File(data) {
       value: (function(data) {
         try {
           if (data.parent) { // prevent recursive - only one parent
-            var _parentPath = data.path.substr(0, data.path.length - 1);
+            var _parentPath = data.path;
             var _location = {location: commonFS_.toRealPath(_parentPath)};
             var _result = native_.callSync('File_statSync', _location);
             var _statObj = native_.getResultObject(_result);