From: Piotr Kosko
Date: Tue, 3 Nov 2015 13:07:39 +0000 (+0100)
Subject: [Filesystem] Fixed path-name issue
X-Git-Tag: submit/tizen/20160524.021316~3
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11d45c5911199917b2d8c50280f07947acb1bfb0;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Filesystem] Fixed path-name issue
[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
---
diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js
index fb450eb6..17fb69d9 100644
--- a/src/filesystem/js/common.js
+++ b/src/filesystem/js/common.js
@@ -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;
diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js
index 973b3c0c..3d7cbb15 100644
--- a/src/filesystem/js/file.js
+++ b/src/filesystem/js/file.js
@@ -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);