[Filesystem] Fixed path-related issues
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 15 Oct 2015 10:52:36 +0000 (12:52 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 15 Oct 2015 13:03:01 +0000 (15:03 +0200)
[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 <p.kosko@samsung.com>
src/filesystem/js/common.js
src/filesystem/js/file.js

index 1bc8ed3..a0010cb 100755 (executable)
@@ -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) {
index 539f3ad..7751273 100755 (executable)
@@ -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) {