[Filesystem] Added new FileMode option and two methods. 00/176300/8
authorArkadiusz Pietraszek <a.pietraszek@partner.samsung.com>
Wed, 18 Apr 2018 07:41:56 +0000 (09:41 +0200)
committerArkadiusz Pietraszek <a.pietraszek@partner.samsung.com>
Mon, 30 Apr 2018 07:10:48 +0000 (07:10 +0000)
Methods added:
StringToArray
ArrayToString

ACR:
http://suprem.sec.samsung.net/jira/browse/TWDAPI-121

Change-Id: If643ebef22b43fdbd61d21f77006a5ab0cf0f04a
Signed-off-by: Szymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Signed-off-by: Arkadiusz Pietraszek <a.pietraszek@partner.samsung.com>
Signed-off-by: Jakub Skowron <j.skowron@samsung.com>
Signed-off-by: Pawel Wasowski <p.wasowski2@partner.samsung.com>
src/filesystem/js/common.js

index adf52c7e514350805061fec593b0a735ee7c2d8d..c473ba574ca87f648e573ec261bc494c712ec751 100644 (file)
@@ -22,17 +22,39 @@ var validator_ = privUtils_.validator;
 var types_ = validator_.Types;
 var native_ = new xwalk.utils.NativeManager(extension);
 
+/*
+ * Create new array-like object of numbers: UTF-16 char codes from string.
+ * As type pass Array, Uint8Array, etc.
+ * Useful for passing data through crosswalk.
+ */
+function StringToArray(str, type) {
+  var len = str.length;
+  var output = new type(len);
+  for (var i = 0; i < len; i++) {
+    output[i] = str.charCodeAt(i);
+  }
+  return output;
+}
+
+/*
+ * Pass array-like object of numbers (Array, Uint8Array, etc.), returns string.
+ * Each char has codepoint equal to value from array cropped with & 0xFF
+ * Useful for passing data through crosswalk.
+ */
+function ArrayToString(data) {
+  var output = '';
+  var len = data.length;
+  for (var i = 0; i < len; i++) {
+    output += String.fromCharCode(data[i] & 0xFF);  // conversion to octet
+  }
+  return output;
+}
+
 function SetReadOnlyProperty(obj, n, v) {
-  Object.defineProperty(obj, n, {
-    value: v,
-    writable: false
-  });
+  Object.defineProperty(obj, n, {value: v, writable: false});
 }
 
-var FileSystemStorageType = {
-  INTERNAL: 'INTERNAL',
-  EXTERNAL: 'EXTERNAL'
-};
+var FileSystemStorageType = {INTERNAL: 'INTERNAL', EXTERNAL: 'EXTERNAL'};
 
 var FileSystemStorageState = {
   MOUNTED: 'MOUNTED',
@@ -40,17 +62,15 @@ var FileSystemStorageState = {
   UNMOUNTABLE: 'UNMOUNTABLE'
 };
 
-var FileMode = {
-  r: 'r',
-  rw: 'rw',
-  w: 'w',
-  a: 'a'
-};
+var FileMode = {a: 'a', r: 'r', rw: 'rw', rwo: 'rwo', w: 'w'};
+
+var BaseSeekPosition = {BEGIN: 'BEGIN', CURRENT: 'CURRENT', END: 'END'};
 
-var tizen24home = "/opt/usr/media";
+var tizen24home = '/opt/usr/media';
 
-//this variable need to match same variable in common/filesystem/filesystem_provider_storage.cc
-var kVirtualRootImages = "images";
+// this variable need to match same variable in
+// common/filesystem/filesystem_provider_storage.cc
+var kVirtualRootImages = 'images';
 
 var commonFS_ = (function() {
   var cacheReady = false;
@@ -60,7 +80,7 @@ var commonFS_ = (function() {
   var uriPrefix = 'file://';
   // special condition for previous versions paths
   // (global paths usage issue workaround)
-  var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan("3.0");
+  var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan('3.0');
   var homeDir = undefined;
 
   function clearCache() {
@@ -77,10 +97,10 @@ var commonFS_ = (function() {
     }
     var imagesPath = cacheVirtualToReal[kVirtualRootImages].path;
 
-    if (imagesPath[imagesPath.length-1] === "/") {
-      homeDir = imagesPath.split("/").slice(0, -2).join("/");
+    if (imagesPath[imagesPath.length - 1] === '/') {
+      homeDir = imagesPath.split('/').slice(0, -2).join('/');
     } else {
-      homeDir = imagesPath.split("/").slice(0, -1).join("/");
+      homeDir = imagesPath.split('/').slice(0, -1).join('/');
     }
   }
 
@@ -130,8 +150,9 @@ var commonFS_ = (function() {
         });
         listenerRegistered = true;
       } catch (e) {
-        privUtils_.log('Failed to register storage change listener, '
-            + 'storage information may be corrupted: ' + e.message);
+        privUtils_.log(
+            'Failed to register storage change listener, ' +
+            'storage information may be corrupted: ' + e.message);
       }
     }
 
@@ -144,8 +165,8 @@ var commonFS_ = (function() {
   }
 
   function removeDotsFromPath(str) {
-    if(str === undefined){
-        return str;
+    if (str === undefined) {
+      return str;
     }
 
     var _pathTokens = str.split('/');
@@ -153,14 +174,15 @@ var commonFS_ = (function() {
     var _fileRealPath = _pathTokens[0];
     _correctDir.push(_pathTokens[0]);
     for (var i = 1; i < _pathTokens.length; ++i) {
-      if(_pathTokens[i] == "..") {
+      if (_pathTokens[i] == '..') {
         if (_fileRealPath == '') {
           _fileRealPath = undefined;
           break;
         }
         var _lastDir = _correctDir.pop();
-        _fileRealPath = _fileRealPath.substring(0, _fileRealPath.length - _lastDir.length - 1);
-      } else if(_pathTokens[i] != "."){
+        _fileRealPath =
+            _fileRealPath.substring(0, _fileRealPath.length - _lastDir.length - 1);
+      } else if (_pathTokens[i] != '.') {
         _fileRealPath += '/' + _pathTokens[i];
         _correctDir.push(_pathTokens[i]);
       }
@@ -189,7 +211,7 @@ var commonFS_ = (function() {
   function convertForEarlierVersionPath(aPath) {
     if (isAppForEarlierVersion) {
       if (aPath && aPath.indexOf(tizen24home) === 0) {
-        privUtils_.log("Converting 2.4 style path to 3.0 pattern");
+        privUtils_.log('Converting 2.4 style path to 3.0 pattern');
         aPath = homeDir + aPath.substr(tizen24home.length);
       }
     }
@@ -231,8 +253,9 @@ var commonFS_ = (function() {
     } else {
       _fileRealPath = aPath;
     }
-    // this line makes that '.' and '..' is supported in paths, but each method handle those cases
-    // and return error (see commonFS_.checkPathWithoutDots() method)
+    // removeDotsFromPath execution here, results with '.' and '..' beeing supported in
+    // paths, next methods throw an error when getting argument with '.' or '..' in it
+    // (see commonFS_.checkPathWithoutDots() method)
     _fileRealPath = removeDotsFromPath(_fileRealPath);
     // convert path to be compatibile with previous version of Tizen
     // (global paths usage issue workaround)
@@ -304,7 +327,7 @@ var commonFS_ = (function() {
         _result.parent = (secondIter) ? null : _fileParentPath;
       } else {
         // '/' dir case
-        _result.path = _pathTokens[last] + lastToken;;
+        _result.path = _pathTokens[last] + lastToken;
         _result.name = '';
         _result.parent = (secondIter) ? null : _fileParentPath;
       }
@@ -332,7 +355,7 @@ var commonFS_ = (function() {
   }
 
   function toCanonicalPath(path) {
-    var result = native_.callSync('FileSystemManager_getCanonicalPath', { "path": path});
+    var result = native_.callSync('FileSystemManager_getCanonicalPath', {'path': path});
     if (native_.isFailure(result)) {
       throw native_.getErrorObject(result);
     }
@@ -352,22 +375,15 @@ var commonFS_ = (function() {
   }
 
   function f_isCorrectRelativePath(relativePath) {
-    return ((0 !== relativePath.indexOf('/'))
-        && (0 !== relativePath.indexOf('\\'))
-        && (-1 === relativePath.indexOf('?'))
-        && (-1 === relativePath.indexOf('*'))
-        && (-1 === relativePath.indexOf(':'))
-        && (-1 === relativePath.indexOf('"'))
-        && (-1 === relativePath.indexOf('<')) && (-1 === relativePath
-        .indexOf('>')));
+    return (
+        (0 !== relativePath.indexOf('/')) && (0 !== relativePath.indexOf('\\')) &&
+        (-1 === relativePath.indexOf('?')) && (-1 === relativePath.indexOf('*')) &&
+        (-1 === relativePath.indexOf(':')) && (-1 === relativePath.indexOf('"')) &&
+        (-1 === relativePath.indexOf('<')) && (-1 === relativePath.indexOf('>')));
   };
 
   function cloneStorage(storage) {
-    return {
-      label: storage.label,
-      type: storage.type,
-      state: storage.state
-    };
+    return {label: storage.label, type: storage.type, state: storage.state};
   }
 
   function getStorage(label) {