From: Piotr Kosko
Date: Tue, 24 May 2016 12:55:19 +0000 (+0200)
Subject: [Common][Filesystem] Added support for global paths from Tizen 2.4 filesystem
X-Git-Tag: submit/tizen/20160525.083856~2^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=700a97f10e3509c027c7d1b3fa1100db60f3b4ba;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Common][Filesystem] Added support for global paths from Tizen 2.4 filesystem
[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//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
---
diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js
index 754d0c48..9e99384a 100644
--- a/src/filesystem/js/common.js
+++ b/src/filesystem/js/common.js
@@ -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;
}
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index b4a6e236..4b9ecbba 100644
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -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);