[Filesystem] Fixed path-related issues 94/70894/1
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 15 Oct 2015 10:52:36 +0000 (12:52 +0200)
committerbg.chun <bg.chun@samsung.com>
Mon, 23 May 2016 07:42:56 +0000 (16:42 +0900)
[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 e5b45f77ecf88a30b6b993ed06ad0eadebd367fa..3d56e38b031788af38cbe775cafbaeecb669daab 100644 (file)
@@ -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) {
index 973b3c0c577c92151f1b8bec36775dfd933924e4..a64539a30bd5a5587ead3971f26bf62426728828 100644 (file)
@@ -436,7 +436,7 @@ function copyTo() {
   }
 
   if (_oldNode.isFile && addFileName) {
-    _realDestinationPath += _realOriginalPath.split('/').pop();
+    _realDestinationPath += '/' + _realOriginalPath.split('/').pop();
   }
 
   if (!args.overwrite) {