From: Piotr Kosko
Date: Thu, 15 Oct 2015 10:52:36 +0000 (+0200)
Subject: [Filesystem] Fixed path-related issues
X-Git-Tag: accepted/tizen/mobile/20151026.233336^2^2~24^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e7180e8b7b36b9a8eeae46a0a5e4598e91f4b63;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 1bc8ed3..a0010cb 100755
--- a/src/filesystem/js/common.js
+++ b/src/filesystem/js/common.js
@@ -106,6 +106,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 = '';
@@ -139,7 +151,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;
}
@@ -158,7 +177,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 539f3ad..7751273 100755
--- a/src/filesystem/js/file.js
+++ b/src/filesystem/js/file.js
@@ -427,7 +427,7 @@ File.prototype.copyTo = function(originFilePath, destinationFilePath, overwrite,
}
if (_oldNode.isFile && addFileName) {
- _realDestinationPath += _realOriginalPath.split('/').pop();
+ _realDestinationPath += '/' + _realOriginalPath.split('/').pop();
}
if (!args.overwrite) {