From: Arkadiusz Pietraszek Date: Wed, 18 Apr 2018 07:41:56 +0000 (+0200) Subject: [Filesystem] Added new FileMode option and two methods. X-Git-Tag: submit/tizen/20180518.121229~12^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a6d1c6d9712362d15543ddfd3fd6a75ad6218d9f;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Added new FileMode option and two methods. Methods added: StringToArray ArrayToString ACR: http://suprem.sec.samsung.net/jira/browse/TWDAPI-121 Change-Id: If643ebef22b43fdbd61d21f77006a5ab0cf0f04a Signed-off-by: Szymon Jastrzebski Signed-off-by: Arkadiusz Pietraszek Signed-off-by: Jakub Skowron Signed-off-by: Pawel Wasowski --- diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js index adf52c7e..c473ba57 100644 --- a/src/filesystem/js/common.js +++ b/src/filesystem/js/common.js @@ -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) {