[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>
_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;
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);