[Common][Filesystem] Added support for global paths from Tizen 2.4 filesystem 30/71230/2
authorPiotr Kosko <p.kosko@samsung.com>
Tue, 24 May 2016 12:55:19 +0000 (14:55 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 25 May 2016 07:18:41 +0000 (09:18 +0200)
[Feature] Now Tizen 3.0 invalid global paths, like '/opt/usr/media/Documents' (valid for 2.4), are
  now converted to Tizen3.0, like '/home/<user>/content/Documents' if application required version
  is lower than 3.0. This commit is to resolve problems existing in some Store apps, when migrating
  to Tizen 3.0.

[Verification] Tested in console. Paths are converted for older applications.
  TCT passrate for filesystem, archive and content is 100%.
  Store application ColorEffectImageEditor.wgt could save files correctly.

Change-Id: I707f70e9f9ef3cb762b6370965d88651ebdec74f
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/filesystem/js/common.js
src/utils/utils_api.js

index 754d0c48824c4acbde928cbc89ada2711858049a..9e99384a3a9d07fad431b8e20d8d8bf1f666dad0 100644 (file)
@@ -47,12 +47,21 @@ var FileMode = {
   a: 'a'
 };
 
+var tizen24home = "/opt/usr/media";
+
+//this variable need to match same variable in common/filesystem/filesystem_provider_storage.cc
+var kVirtualRootImages = "images";
+
 var commonFS_ = (function() {
   var cacheReady = false;
   var listenerRegistered = false;
   var cacheVirtualToReal = {};
   var cacheStorages = [];
   var uriPrefix = 'file://';
+  // special condition for previous versions paths
+  // (global paths usage issue workaround)
+  var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan("3.0");
+  var homeDir = undefined;
 
   function clearCache() {
     cacheVirtualToReal = {};
@@ -60,6 +69,21 @@ var commonFS_ = (function() {
     cacheReady = false;
   }
 
+  // initalize home directory for correct mapping global paths from tizen 2.4
+  // (global paths usage issue workaround)
+  function initHomeDir(aPath) {
+    if (homeDir || !isAppForEarlierVersion) {
+      return;
+    }
+    var imagesPath = cacheVirtualToReal[kVirtualRootImages].path;
+
+    if (imagesPath[imagesPath.length-1] === "/") {
+      homeDir = imagesPath.split("/").slice(0, -2).join("/");
+    } else {
+      homeDir = imagesPath.split("/").slice(0, -1).join("/");
+    }
+  }
+
   function initCache() {
     if (cacheReady) {
       return;
@@ -79,6 +103,9 @@ var commonFS_ = (function() {
         state: FileSystemStorageState.MOUNTED
       };
     }
+    // initalize home directory for correct mapping global paths from tizen 2.4
+    // (global paths usage issue workaround)
+    initHomeDir();
 
     var result = native_.callSync('FileSystemManager_fetchStorages', {});
     if (native_.isFailure(result)) {
@@ -159,6 +186,16 @@ var commonFS_ = (function() {
     return true;
   }
 
+  function convertForEarlierVersionPath(aPath) {
+    if (isAppForEarlierVersion) {
+      if (aPath && aPath.indexOf(tizen24home) === 0) {
+        console.log("Converting 2.4 style path to 3.0 pattern");
+        aPath = homeDir + aPath.substr(tizen24home.length);
+      }
+    }
+    return aPath;
+  }
+
   function toRealPath(aPath) {
     var _fileRealPath = '';
 
@@ -197,6 +234,17 @@ var commonFS_ = (function() {
     // this line makes that '.' and '..' is supported in paths, but each method handle those cases
     // and return error (see commonFS_.checkPathWithoutDots() method)
     _fileRealPath = removeDotsFromPath(_fileRealPath);
+    // convert path to be compatibile with previous version of Tizen
+    // (global paths usage issue workaround)
+    _fileRealPath = convertForEarlierVersionPath(_fileRealPath);
+    // 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;
   }
 
index b4a6e236287647389e006e1156d6d4f414c3a330..4b9ecbba0fdf41c78633c4c6adcb4f48d409522d 100644 (file)
@@ -229,34 +229,34 @@ Utils.prototype.checkPrivilegeAccess = function(privilege) {
   }
 };
 
-Utils.prototype.checkPrivilegeAccess4Ver = function(new_ver, new_priv, old_priv) {
+Utils.prototype.isAppVersionEarlierThan= function(ver) {
   var app_ver = this.getPkgApiVersion();
 
-  var arr_new_ver = new_ver.split(".");
-  var arr_app_ver = app_ver.split(".");
-  var num_new;
+  var arr_ver = ver.split(".");   // reference version
+  var arr_app_ver = app_ver.split(".");  // application version
+  var num_ver;
   var num_app;
-  var sel = 0;
 
   var i;
-  var length = Math.min(arr_new_ver.length, arr_app_ver.length);
+  var length = Math.min(arr_ver.length, arr_app_ver.length);
   for (i = 0; i < length; i++) {
-    num_new = parseInt(arr_new_ver[i]);
+    num_ver = parseInt(arr_ver[i]);
     num_app = parseInt(arr_app_ver[i]);
-    if (num_app < num_new) {
-      sel = 1;
-      break;
-    } else if (num_app > num_new) {
-      sel = -1;
-      break;
+    if (num_app < num_ver) {
+      return true;
+    } else if (num_app > num_ver) {
+      return false;
     }
   }
 
-  if (sel == 0 && arr_new_ver.length > arr_app_ver.length) {
-    sel = 1;
+  if (arr_ver.length > arr_app_ver.length) {
+    return true;
   }
+  return false;
+}
 
-  if (sel != 1) {
+Utils.prototype.checkPrivilegeAccess4Ver = function(new_ver, new_priv, old_priv) {
+  if (this.isAppVersionEarlierThan(new_ver)) {
     this.checkPrivilegeAccess(new_priv);
   } else if (old_priv != undefined) {
     this.checkPrivilegeAccess(old_priv);