From: Piotr Kosko
Date: Thu, 15 Oct 2015 10:52:36 +0000 (+0200)
Subject: [Filesystem] Fixed path-related issues
X-Git-Tag: submit/tizen/20160524.021316~6
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4352b195a1b022234228ad5cecc63cf04d949c2d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Filesystem] Fixed path-related issues
[Features] Fixed issues:
1. resolve "documents/" works as resolving "documents"
2. multiple "/" is filepaths are merged to single one
[Verification] Code compiles without errors.
TCTs of Filesystem, Calendar, Alarm, Archive and Exif return 100% passrate.
Scenarios with results below:
1.
tizen.filesystem.resolve(
'images/',
function(dir) {
var a = dir.createDirectory('testt');
console.log("path: " + a.path + " fullPath: " + a.fullPath);
}, function(e) {
console.log("Error: " + e.message);
}, "rw"
);
---------
path: images/ fullPath: images/testt
2.
tizen.filesystem.resolve(
'images/testt/',
function(dir) {
console.log("Mount point Name is " + dir.path);
console.log("path: " + dir.path + " fullPath: " + dir.fullPath);
}, function(e) {
console.log("Error: " + e.message);
}, "rw"
);
---------
path: images/ fullPath: images/testt
3.
tizen.filesystem.resolve(
'images//////testt/',
function(dir) {
console.log("Mount point Name is " + dir.path);
console.log("path: " + dir.path + " fullPath: " + dir.fullPath);
}, function(e) {
console.log("Error: " + e.message);
}, "rw"
);
---------
path: images/ fullPath: images/testt
Change-Id: I66ce92a5207148dfa82109e187b8e4f58727aead
Signed-off-by: Piotr Kosko
---
diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js
index e5b45f77..3d56e38b 100644
--- a/src/filesystem/js/common.js
+++ b/src/filesystem/js/common.js
@@ -111,6 +111,18 @@ var commonFS_ = (function() {
cacheReady = true;
}
+ function mergeMultipleSlashes(str) {
+ var s = str[0];
+ var resStr = s;
+ for (var i=1; i < str.length; ++i ) {
+ if (!(str[i] === s && str[i] === '/')) {
+ s = str[i];
+ resStr+=str[i];
+ }
+ }
+ return resStr;
+ }
+
function toRealPath(aPath) {
var _fileRealPath = '';
@@ -144,7 +156,14 @@ var commonFS_ = (function() {
} else {
_fileRealPath = aPath;
}
-
+ // if path is valid try to cut last '/' if it is present
+ if (_fileRealPath) {
+ _fileRealPath = mergeMultipleSlashes(_fileRealPath);
+ var lastCharIndex = _fileRealPath.length-1;
+ if (_fileRealPath[lastCharIndex] === '/') {
+ _fileRealPath = _fileRealPath.substr(0,lastCharIndex);
+ }
+ }
return _fileRealPath;
}
@@ -163,7 +182,12 @@ var commonFS_ = (function() {
}
}
- return aPath;
+ // cutting of last '/' if it is present
+ var lastCharIndex = aPath.length-1;
+ if (aPath[lastCharIndex] === '/') {
+ aPath = aPath.substr(0,lastCharIndex);
+ }
+ return mergeMultipleSlashes(aPath);
}
function getFileInfo(aStatObj, secondIter, aMode) {
diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js
index 973b3c0c..a64539a3 100644
--- a/src/filesystem/js/file.js
+++ b/src/filesystem/js/file.js
@@ -436,7 +436,7 @@ function copyTo() {
}
if (_oldNode.isFile && addFileName) {
- _realDestinationPath += _realOriginalPath.split('/').pop();
+ _realDestinationPath += '/' + _realOriginalPath.split('/').pop();
}
if (!args.overwrite) {